Skip to content

Commit

Permalink
Add CNODEBIN to allow custom cardano-node name
Browse files Browse the repository at this point in the history
* Add CNODEBIN to allow custom cardano-node name - Closes #1071 

* As first auto-detection, if CNODEBIN is not specified - try using CCLI folder - before using ~/.cabal/bin
  • Loading branch information
rdlrt committed Sep 28, 2021
1 parent 66ae541 commit 16fa2d7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
8 changes: 1 addition & 7 deletions scripts/cnode-helper-scripts/cncli.sh
Expand Up @@ -522,12 +522,6 @@ cncliMigrateBlocklog() {
cncliPTsendtip() {
[[ ${NWMAGIC} -ne 764824073 ]] && echo "PoolTool sendtip only available on MainNet, exiting!" && exit 1
[[ -z ${POOL_ID} || -z ${POOL_TICKER} || -z ${PT_API_KEY} ]] && echo "'POOL_ID' and/or 'POOL_TICKER' and/or 'PT_API_KEY' not set in $(basename "$0"), exiting!" && exit 1

# Generate a temporary pooltool config
if ! cnode_path=$(command -v cardano-node 2>/dev/null); then
echo "ERROR: cardano-node not in PATH, please manually set CCLI in env file"
exit 1
fi
pt_config="${TMP_DIR}/$(basename ${CNODE_HOME})-pooltool.json"
bash -c "cat <<-'EOF' > ${pt_config}
{
Expand All @@ -542,7 +536,7 @@ cncliPTsendtip() {
]
}
EOF"
${CNCLI} sendtip --config "${pt_config}" --cardano-node "${cnode_path}"
${CNCLI} sendtip --config "${pt_config}" --cardano-node "${CNODEBIN}"
}

#################################
Expand Down
6 changes: 3 additions & 3 deletions scripts/cnode-helper-scripts/cnode.sh
Expand Up @@ -21,7 +21,7 @@
[[ -z ${CNODE_LISTEN_IP6} ]] && CNODE_LISTEN_IP6=::

if [[ -S "${CARDANO_NODE_SOCKET_PATH}" ]]; then
if pgrep -f "[c]ardano-node.*.${CARDANO_NODE_SOCKET_PATH}"; then
if pgrep -f "$(basename ${CNODEBIN}).*.${CARDANO_NODE_SOCKET_PATH}"; then
echo "ERROR: A Cardano node is already running, please terminate this node before starting a new one with this script."
exit 1
else
Expand All @@ -41,7 +41,7 @@ host_addr=()
[[ ${IP_VERSION} = "6" || ${IP_VERSION} = "mix" ]] && host_addr+=("--host-ipv6-addr" "${CNODE_LISTEN_IP6}")

if [[ -f "${POOL_DIR}/${POOL_OPCERT_FILENAME}" && -f "${POOL_DIR}/${POOL_VRF_SK_FILENAME}" && -f "${POOL_DIR}/${POOL_HOTKEY_SK_FILENAME}" ]]; then
cardano-node "${CPU_RUNTIME[@]}" run \
"${CNODEBIN}" "${CPU_RUNTIME[@]}" run \
--topology "${TOPOLOGY}" \
--config "${CONFIG}" \
--database-path "${DB_DIR}" \
Expand All @@ -52,7 +52,7 @@ if [[ -f "${POOL_DIR}/${POOL_OPCERT_FILENAME}" && -f "${POOL_DIR}/${POOL_VRF_SK_
--port ${CNODE_PORT} \
"${host_addr[@]}"
else
cardano-node "${CPU_RUNTIME[@]}" run \
"${CNODEBIN}" "${CPU_RUNTIME[@]}" run \
--topology "${TOPOLOGY}" \
--config "${CONFIG}" \
--database-path "${DB_DIR}" \
Expand Down
2 changes: 1 addition & 1 deletion scripts/cnode-helper-scripts/deploy-as-systemd.sh
Expand Up @@ -31,7 +31,7 @@ User=$USER
LimitNOFILE=1048576
WorkingDirectory=${CNODE_HOME}/scripts
ExecStart=/bin/bash -l -c \"exec ${CNODE_HOME}/scripts/cnode.sh\"
ExecStop=/bin/bash -l -c \"exec kill -2 \$(ps -ef | grep [c]ardano-node.*.${CNODE_HOME}/ | tr -s ' ' | cut -d ' ' -f2) &>/dev/null\"
ExecStop=/bin/bash -l -c \"exec kill -2 \$(ps -ef | grep ${CNODEBIN}.*.${CNODE_HOME}/ | tr -s ' ' | cut -d ' ' -f2) &>/dev/null\"
KillSignal=SIGINT
SuccessExitStatus=143
StandardOutput=syslog
Expand Down
28 changes: 19 additions & 9 deletions scripts/cnode-helper-scripts/env
Expand Up @@ -6,8 +6,9 @@
# Leave as is if unsure #
######################################

#CCLI="${HOME}/.cabal/bin/cardano-cli" # Override automatic detection of path to cardano-cli executable
#CNCLI="${HOME}/.cargo/bin/cncli" # Override automatic detection of path to cncli executable (https://github.com/AndrewWestberg/cncli)
#CNODEBIN="${HOME}/.cabal/bin/cardano-node" # Override automatic detection of cardano-node executable
#CCLI="${HOME}/.cabal/bin/cardano-cli" # Override automatic detection of cardano-cli executable
#CNCLI="${HOME}/.cargo/bin/cncli" # Override automatic detection of executable (https://github.com/AndrewWestberg/cncli)
#CNODE_HOME="/opt/cardano/cnode" # Override default CNODE_HOME path (defaults to /opt/cardano/cnode)
CNODE_PORT=6000 # Set node port
#CONFIG="${CNODE_HOME}/files/config.json" # Override automatic detection of node config path
Expand Down Expand Up @@ -109,16 +110,25 @@ telegramSend() {
[[ -z "${CCLI}" ]] && CCLI=$(command -v cardano-cli)
if [[ -z "${CCLI}" ]]; then
if [[ -f "${HOME}/.cabal/bin/cardano-cli" ]]; then
# Assumption being made that cardano-cli and cardano-node are both present, if not - prereqs and build instructions were not followed
export PATH="${HOME}/.cabal/bin":$PATH
CCLI=$(command -v cardano-cli)
else
echo "You do not have a cardano-cli binary available in \$PATH."
return 1
fi
else
CCLI_PARENT="$(dirname ${CCLI})"
export PATH="${CCLI_PARENT}":$PATH
fi

[[ -z "${CNODEBIN}" ]] && CNODEBIN=$(command -v cardano-node)
if [[ -z "${CNODEBIN}" ]]; then
if [[ -f "$(dirname ${CCLI})"/cardano-node ]]; then
CNODEBIN="$(dirname ${CCLI})"/cardano-node
elif [[ -f "${HOME}/.cabal/bin/cardano-node" ]]; then
export PATH="${HOME}/.cabal/bin":$PATH
CNODEBIN=$(command -v cardano-node)
else
echo "You do not have a cardano-node binary available in \$PATH."
return 1
fi
fi

if [[ -z "${CNCLI}" ]]; then
Expand All @@ -130,7 +140,7 @@ fi
[[ -z "${CNODE_HOME}" ]] && CNODE_HOME=/opt/cardano/cnode

if [[ -z "${SOCKET}" ]]; then
if [[ "$(ps -ef | grep "[c]ardano-node.*.port ${CNODE_PORT}")" =~ --socket-path[[:space:]]([^[:space:]]+) ]]; then
if [[ "$(ps -ef | grep "$(basename ${CNODEBIN}).*.port ${CNODE_PORT} | grep -v grep")" =~ --socket-path[[:space:]]([^[:space:]]+) ]]; then
export CARDANO_NODE_SOCKET_PATH="${BASH_REMATCH[1]}"
elif [[ ${OFFLINE_MODE} = "Y" ]]; then
export CARDANO_NODE_SOCKET_PATH="${CNODE_HOME}/sockets/node0.socket"
Expand All @@ -144,7 +154,7 @@ fi
export SOCKET="${CARDANO_NODE_SOCKET_PATH}" # For compatibility with those who havn't yet upgraded cnode.sh

if [[ -z "${CONFIG}" ]]; then
if [[ "$(ps -ef | grep "[c]ardano-node.*.port ${CNODE_PORT}")" =~ --config[[:space:]]([^[:space:]]+) ]]; then
if [[ "$(ps -ef | grep "$(basename ${CNODEBIN}).*.port ${CNODE_PORT} | grep -v grep")" =~ --config[[:space:]]([^[:space:]]+) ]]; then
CONFIG=${BASH_REMATCH[1]}
elif [[ -f "${CNODE_HOME}/files/config.json" ]]; then
CONFIG="${CNODE_HOME}/files/config.json"
Expand Down Expand Up @@ -250,7 +260,7 @@ BLOCKLOG_DB="${BLOCKLOG_DIR}/blocklog.db"
[[ -z "${IP_VERSION}" ]] && IP_VERSION=4
IP_VERSION=$(tr '[:upper:]' '[:lower:]' <<< "${IP_VERSION}")
[[ -z ${USE_EKG} ]] && USE_EKG='Y'
CNODE_PID=$(pgrep -fn "[c]ardano-node.*.--port ${CNODE_PORT}")
CNODE_PID=$(pgrep -fn "$(basename ${CNODEBIN}).*.--port ${CNODE_PORT}")

if [[ -n "${CNODE_PID}" ]]; then
if [[ "${USE_EKG}" == "N" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions scripts/cnode-helper-scripts/gLiveView.sh
Expand Up @@ -54,7 +54,7 @@ setTheme() {
# Do NOT modify code below #
######################################

GLV_VERSION=v1.22.2
GLV_VERSION=v1.22.3

PARENT="$(dirname $0)"

Expand Down Expand Up @@ -550,7 +550,7 @@ if [[ ${SHELLEY_TRANS_EPOCH} -eq -1 ]]; then
printf "\n After successful node boot or when sync to shelley era has been reached, calculations will be correct\n"
waitToProceed && clrScreen
fi
version=$("$(command -v cardano-node)" version)
version=$("${CNODEBIN}" version)
node_version=$(grep "cardano-node" <<< "${version}" | cut -d ' ' -f2)
node_rev=$(grep "git rev" <<< "${version}" | cut -d ' ' -f3 | cut -c1-8)
cncli_port=$(ss -tnp state established "( dport = :${CNODE_PORT} )" 2>/dev/null | grep cncli | awk '{print $3}' | cut -d: -f2)
Expand Down Expand Up @@ -607,7 +607,7 @@ while true; do
printf "${style_status_3}Connection to node lost, retrying (${fail_count}/${RETRIES})!${NC}"
waitForInput && continue
elif [[ ${fail_count} -ne 0 ]]; then # was failed but now ok, re-check
CNODE_PID=$(pgrep -fn "[c]ardano-node*.*--port ${CNODE_PORT}")
CNODE_PID=$(pgrep -fn "$(basename ${CNODEBIN}).*.port ${CNODE_PORT}")
version=$("$(command -v cardano-node)" version)
node_version=$(grep "cardano-node" <<< "${version}" | cut -d ' ' -f2)
node_rev=$(grep "git rev" <<< "${version}" | cut -d ' ' -f3 | cut -c1-8)
Expand Down

0 comments on commit 16fa2d7

Please sign in to comment.