Skip to content

Commit

Permalink
deploy-as-systemd.sh option for mithril signer
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBenson committed Oct 21, 2023
1 parent fdf8dbf commit a5fe8ca
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/cnode-helper-scripts/deploy-as-systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ if [[ ${yn} = [Yy]* ]]; then
./submitapi.sh -d
fi

if command -v mithril-signer >/dev/null 2>&1 ; then
echo -e "\e32m~~ Mithril Signer ~~\e[0m"
echo "launches the mithril-signer.sh script to deploy mithril"
echo
./mithril.sh -d
fi

if command -v ogmios >/dev/null 2>&1 ; then
echo -e "\e32m~~ Cardano Ogmios Server ~~\e[0m"
echo "launches the ogmios.sh script to deploy ogmios"
Expand Down
138 changes: 138 additions & 0 deletions scripts/cnode-helper-scripts/mithril-signer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env bash
# shellcheck disable=SC2086
#shellcheck source=/dev/null

. "$(dirname $0)"/env offline

######################################
# User Variables - Change as desired #
# Common variables set in env file #
######################################

#MITHRILBIN="${HOME}"/.local/bin/mithril-signer # Path for mithril-signer binary, if not in $PATH
#HOSTADDR=127.0.0.1 # Default Listen IP/Hostname for Mithril Signer Server
MITHRIL_HOME="/opt/mithril/mithril-signer"

######################################
# Do NOT modify code below #
######################################

#####################
# Functions #
#####################

usage() {
cat <<-EOF
Usage: $(basename "$0") [-d]
Cardano Mithril signer wrapper script !!
-d Deploy mithril-signer as a systemd service
EOF
exit 1
}

set_defaults() {
[[ -z "${MITHRILBIN}" ]] && MITHRILBIN="${HOME}"/.local/bin/mithril-signer
[[ -z "${HOSTADDR}" ]] && HOSTADDR=127.0.0.1
# [[ -z "${HOSTPORT}" ]] && HOSTPORT=1337
if [[ -n "${NETWORK}" ]]; then
case "${NETWORK}" in
mainnet|preprod)
RELEASE="release"
AGGREGATOR_ENDPOINT=
;;
*)
RELEASE="pre-release"
;;
esac
sudo bash -c 'cat > ${MITHRIL_HOME}/service.env << EOF
AGGREGATOR_ENDPOINT="https://aggregator.${RELEASE}-${NETWORK}.api.mithril.network/aggregator"
KES_SECRET_KEY_PATH="${POOL_DIR}/${POOL_HOTKEY_SK_FILENAME}"
OPERATIONAL_CERTIFICATE_PATH="${POOL_DIR}/${POOL_OPCERT_FILENAME}"
PARTY_ID=$(cat ${POOL_DIR}/${POOL_ID_FILENAME})
DB_DIRECTORY="${CNODE_HOME}/db"
CARDANO_CLI_PATH="${HOME}/.local/bin/cardano-cli"
DATA_STORES_DIRECTORY="${MITHRIL_HOME}/data-stores"
ERA_READER_ADAPTER_TYPE="cardano-chain"
ERA_READER_ADDRESS="https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/${RELEASE}-${NETWORK}/era.addr"
ERA_READER_VKEY="https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/${RELEASE}-${NETWORK}/era.vkey"
ERA_READER_ADAPTER_PARAMS=$(jq -nc --arg address $(wget -q -O - "${ERA_READER_ADDRESS}") --arg verification_key $(wget -q -O - "${ERA_READER_VKEY}") '{"address": $address, "verification_key": $verification_key}')
GENESIS_VERIFICATION_KEY=$(curl -s https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/${RELEASE}-${NETWORK}/genesis.vkey)
EOF'
else
echo "ERROR: NETWORK not set in env file, please set and re-run!!"
fi
}

pre_startup_sanity() {
[[ ! -f "${MITHRILBIN}" ]] && MITHRILBIN="$(command -v mithril-signer)"
if [[ ! -S "${CARDANO_NODE_SOCKET_PATH}" ]]; then
echo "ERROR: Could not locate socket file at ${CARDANO_NODE_SOCKET_PATH}, the node may not have completed startup !!"
exit 1
fi
# Move logs to archive
[[ -f "${LOG_DIR}"/mithril-signer.log ]] && mv "${LOG_DIR}"/mithril-signer.log "${LOG_DIR}"/archive/
}

deploy_systemd() {
echo "Deploying ${CNODE_VNAME}-mithril-signer as systemd service.."
sudo bash -c "cat <<-'EOF' > /etc/systemd/system/${CNODE_VNAME}-mithril-signer.service
[Unit]
Description=Cardano Mithril signer service
StartLimitIntervalSec=0
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
RestartSec=5
User=${USER}
EnvironmentFile=${MITHRIL_HOME}/service.env
ExecStart=/bin/bash -l -c \"exec ${HOME}/.local/bin/mithril-signer -vv
KillSignal=SIGINT
SuccessExitStatus=143
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=${CNODE_VNAME}-mithril-signer
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF" && echo "${CNODE_VNAME}-mithril-signer.service deployed successfully!!" && sudo systemctl daemon-reload && sudo systemctl enable ${CNODE_VNAME}-mithril-signer.service
}

###################
# Execution #
###################

# Parse command line options
while getopts :d opt; do
case ${opt} in
d ) DEPLOY_SYSTEMD="Y" ;;
\? ) usage ;;
esac
done

# Check if env file is missing in current folder (no update checks as will mostly run as daemon), source env if present
[[ ! -f "$(dirname $0)"/env ]] && echo -e "\nCommon env file missing, please ensure latest guild-deploy.sh was run and this script is being run from ${CNODE_HOME}/scripts folder! \n" && exit 1
. "$(dirname $0)"/env
case $? in
1) echo -e "ERROR: Failed to load common env file\nPlease verify set values in 'User Variables' section in env file or log an issue on GitHub" && exit 1;;
2) clear ;;
esac

# Set defaults and do basic sanity checks
set_defaults
#Deploy systemd if -d argument was specified
if [[ "${DEPLOY_SYSTEMD}" == "Y" ]]; then
deploy_systemd && exit 0
exit 2
fi
pre_startup_sanity

# Run Mithril Signer Server
"${MITHRILBIN}" -vvv >> "${LOG_DIR}"/mithril-signer.log 2>&1

0 comments on commit a5fe8ca

Please sign in to comment.