Skip to content

Commit

Permalink
systemd deployment fix and int update for prereqs and cncli
Browse files Browse the repository at this point in the history
  • Loading branch information
Scitz0 committed Nov 29, 2020
1 parent 696efa0 commit aa055e6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
44 changes: 40 additions & 4 deletions scripts/cnode-helper-scripts/cncli.sh
Expand Up @@ -24,6 +24,7 @@ POOL_TICKER="" # POOLTOOL sendtip: set the pools tick
#CONFIRM_SLOT_CNT=600 # CNCLI validate: require at least these many slots to have passed before validating
#CONFIRM_BLOCK_CNT=15 # CNCLI validate: require at least these many blocks on top of minted before validating
#TIMEOUT_LEDGER_STATE=300 # CNCLI leaderlog: timeout in seconds for ledger-state query
#BATCH_AUTO_UPDATE=N # Set to Y to automatically update the script if a new version is available without user interaction

######################################
# Do NOT modify code below #
Expand Down Expand Up @@ -213,23 +214,58 @@ cncliInit() {
[[ -z "${TIMEOUT_LEDGER_STATE}" ]] && TIMEOUT_LEDGER_STATE=300
[[ -z "${PT_HOST}" ]] && PT_HOST="127.0.0.1"
[[ -z "${PT_PORT}" ]] && PT_PORT="${CNODE_PORT}"
[[ -z "${BATCH_AUTO_UPDATE}" ]] && BATCH_AUTO_UPDATE=N

PARENT="$(dirname $0)"
PARENT="$(dirname $0)"
if [[ ! -f "${PARENT}"/env ]]; then
echo "ERROR: could not find common env file, please update and run 'prereqs.sh -h' to show options"
echo "ERROR: could not find common env file, please download and run 'prereqs.sh -h' to show options"
exit 1
fi
if ! . "${PARENT}"/env; then exit 1; fi

[[ ! -f "${CNCLI}" ]] && echo "ERROR: failed to locate cncli executable, please update and run 'prereqs.sh -h' to show options" && exit 1

if [[ $(grep "_HOME=" "${PARENT}"/env) =~ ^#?([^[:space:]]+)_HOME ]]; then
vname=$(tr '[:upper:]' '[:lower:]' <<< "${BASH_REMATCH[1]}")
else
echo "failed to get cnode instance name from env file, aborting!"
exit 1
fi

# Check if cncli.sh update is available
[[ -f "${PARENT}"/.env_branch ]] && BRANCH="$(cat ${PARENT}/.env_branch)" || BRANCH="master"
URL="https://raw.githubusercontent.com/cardano-community/guild-operators/${BRANCH}/scripts/cnode-helper-scripts"
if curl -s -m 10 -o "${PARENT}"/cncli.sh.tmp ${URL}/cncli.sh; then
sed -e "s@/opt/cardano/[c]node@/opt/cardano/${vname}@g" -e "s@[C]NODE_HOME@${BASH_REMATCH[1]}_HOME@g" -i "${PARENT}"/cncli.sh.tmp
TEMPL_CMD=$(awk '/^# Do NOT modify/,0' "${PARENT}"/cncli.sh)
TEMPL2_CMD=$(awk '/^# Do NOT modify/,0' "${PARENT}"/cncli.sh.tmp)
if [[ "$(echo ${TEMPL_CMD} | sha256sum)" != "$(echo ${TEMPL2_CMD} | sha256sum)" ]]; then
update='N'
if [[ ${BATCH_AUTO_UPDATE} = 'Y' ]]; then
update='Y'
elif [[ $- =~ i ]]; then
echo -e "\nA new version of cncli script is available"
echo -e "\nPress 'u' to update to latest version, or any other key to continue\n"
read -r -n 1 -s answer
[[ ${answer} = "u" ]] && update='Y'
echo
fi
if [[ ${update} = 'Y' ]]; then
cp "${PARENT}"/cncli.sh "${PARENT}/cncli.sh_bkp$(date +%s)"
STATIC_CMD=$(awk '/#!/{x=1}/^# Do NOT modify/{exit} x' "${PARENT}"/cncli.sh)
printf '%s\n%s\n' "$STATIC_CMD" "$TEMPL2_CMD" > "${PARENT}"/cncli.sh.tmp
mv -f "${PARENT}"/cncli.sh.tmp "${PARENT}"/cncli.sh && \
chmod 750 "${PARENT}"/cncli.sh && \
echo -e "Update applied successfully!\n\nPlease run cncli again!" && \
exit 0 || {
echo -e "${FG_RED}Update failed!${NC}\n\nPlease use prereqs.sh or manually download to update cncli"
exit 1
}
fi
fi
fi
rm -f "${PARENT}"/cncli.sh.tmp

[[ ! -f "${CNCLI}" ]] && echo "ERROR: failed to locate cncli executable, please update and run 'prereqs.sh -h' to show options" && exit 1

return 0
}

Expand Down
35 changes: 24 additions & 11 deletions scripts/cnode-helper-scripts/deploy-as-systemd.sh
@@ -1,9 +1,16 @@
#!/bin/bash
# shellcheck disable=SC1090

vname=%vname%
PARENT="$(dirname $0)"

. "$(dirname "$0")"/env &>/dev/null # ignore any error
if [[ $(grep "_HOME=" "${PARENT}"/env) =~ ^#?([^[:space:]]+)_HOME ]]; then
vname=$(tr '[:upper:]' '[:lower:]' <<< "${BASH_REMATCH[1]}")
else
echo "failed to get cnode instance name from env file, aborting!"
exit 1
fi

. "${PARENT}"/env offline

echo -e "\e[32m~~ Cardano Node ~~\e[0m"
echo "launches the main cnode.sh script to start cardano-node"
Expand Down Expand Up @@ -119,17 +126,23 @@ AccuracySec=1s
WantedBy=timers.target ${vname}.service
EOF"
else
if [[ -f /etc/systemd/system/${vname}-topologyupdater.timer ]]; then
sudo systemctl disable ${vname}-topologyupdater.timer
sudo rm -f /etc/systemd/system/${vname}-topologyupdater.timer
if [[ -f /etc/systemd/system/${vname}-tu-fetch.service ]]; then
sudo systemctl disable ${vname}-tu-fetch.service
sudo rm -f /etc/systemd/system/${vname}-tu-fetch.service
fi
if [[ -f /etc/systemd/system/${vname}-tu-push.timer ]]; then
sudo systemctl disable ${vname}-tu-push.timer
sudo rm -f /etc/systemd/system/${vname}-tu-push.timer
fi
if [[ -f /etc/systemd/system/${vname}-tu-push.service ]]; then
sudo rm -f /etc/systemd/system/${vname}-tu-push.service
fi
if [[ -f /etc/systemd/system/${vname}-topologyupdater.service ]]; then
sudo systemctl disable ${vname}-topologyupdater.service
sudo rm -f /etc/systemd/system/${vname}-topologyupdater.service
if [[ -f /etc/systemd/system/${vname}-tu-restart.timer ]]; then
sudo systemctl disable ${vname}-tu-restart.timer
sudo rm -f /etc/systemd/system/${vname}-tu-restart.timer
fi
if [[ -f /etc/systemd/system/${vname}.timer ]]; then
sudo systemctl disable ${vname}.timer
sudo rm -f /etc/systemd/system/${vname}.timer
if [[ -f /etc/systemd/system/${vname}-tu-restart.service ]]; then
sudo rm -f /etc/systemd/system/${vname}-tu-restart.service
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/cnode-helper-scripts/gLiveView.sh
Expand Up @@ -158,7 +158,7 @@ if curl -s -m ${CURL_TIMEOUT} -o /tmp/gLiveView.sh "${URL}/gLiveView.sh" 2>/dev/
cp -f /tmp/gLiveView.sh "${PARENT}/gLiveView.sh" && \
chmod 750 "${PARENT}/gLiveView.sh" && \
myExit 0 "Update applied successfully!\n\nPlease start Guild LiveView again!" || \
myExit 1 "${RED}Update failed!${NC}\n\nPlease use prereqs.sh or manually download to update gLiveView"
myExit 1 "${FG_RED}Update failed!${NC}\n\nPlease use prereqs.sh or manually download to update gLiveView"
fi
fi
else
Expand Down
15 changes: 13 additions & 2 deletions scripts/cnode-helper-scripts/prereqs.sh
Expand Up @@ -90,11 +90,24 @@ fi

REPO="https://github.com/cardano-community/guild-operators"
REPO_RAW="https://raw.githubusercontent.com/cardano-community/guild-operators"
URL_RAW="${REPO_RAW}/${BRANCH}"

SUDO='Y';
[[ "${SUDO}" = 'Y' ]] && sudo="sudo" || sudo=""
[[ "${SUDO}" = 'Y' && $(id -u) -eq 0 ]] && err_exit "Please run as non-root user."

PARENT="$(dirname $0)"
if curl -s -m ${CURL_TIMEOUT} -o "${PARENT}"/prereqs.sh.tmp ${URL_RAW}/scripts/prereqs.sh 2>/dev/null; then
if ! cmp --silent "${PARENT}"/prereqs.sh "${PARENT}"/prereqs.sh.tmp; then
if get_answer "A new version of prereqs script available, do you want to download the latest version?"; then
mv -f "${PARENT}"/prereqs.sh.tmp "${PARENT}"/prereqs.sh
echo -e "Update applied successfully!\n\nPlease re-run the script again!"
exit
fi
fi
fi
rm -f "${PARENT}"/prereqs.sh.tmp

if [ "${INTERACTIVE}" = 'Y' ]; then
clear;
CNODE_PATH=$(get_input "Please enter the project path" ${CNODE_PATH})
Expand Down Expand Up @@ -250,7 +263,6 @@ $sudo chown -R "$U_ID":"$G_ID" "${CNODE_HOME}" 2>/dev/null

echo "Downloading files..."

URL_RAW="${REPO_RAW}/${BRANCH}"
pushd "${CNODE_HOME}"/files >/dev/null || err_exit
curl -s -m ${CURL_TIMEOUT} -o config.json.tmp ${URL_RAW}/files/config-combinator.json 2>/dev/null

Expand Down Expand Up @@ -305,7 +317,6 @@ curl -s -m ${CURL_TIMEOUT} -o sLiveView.sh ${URL_RAW}/scripts/cnode-helper-scrip
curl -s -m ${CURL_TIMEOUT} -o gLiveView.sh.tmp ${URL_RAW}/scripts/cnode-helper-scripts/gLiveView.sh
curl -s -m ${CURL_TIMEOUT} -o deploy-as-systemd.sh ${URL_RAW}/scripts/cnode-helper-scripts/deploy-as-systemd.sh
curl -s -m ${CURL_TIMEOUT} -o cncli.sh.tmp ${URL_RAW}/scripts/cnode-helper-scripts/cncli.sh
sed -e "s@%vname%@${CNODE_NAME}@g" -i deploy-as-systemd.sh
sed -e "s@/opt/cardano/cnode@${CNODE_HOME}@g" -e "s@CNODE_HOME@${CNODE_VNAME}_HOME@g" -i ./*.*

### Update file retaining existing custom configs
Expand Down

0 comments on commit aa055e6

Please sign in to comment.