From 6e93ab4eb029ecfd395ff1ccc5a3c4e29a960b0b Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 12:23:06 +0530 Subject: [PATCH] Trap signals on shutdown and clean up in lighthouse nodes --- .../cerc-fixturenet-eth-geth/run-el.sh | 4 +++- .../genesis/cl/beacon_node.sh | 2 +- .../genesis/cl/validator_client.sh | 2 +- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh b/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh index eca702e4..aed555ef 100755 --- a/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh +++ b/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh @@ -13,13 +13,14 @@ cd /opt/testnet/build/el python3 -m http.server 9898 & cd $HOME_DIR -START_CMD="geth --datadir=~/ethdata" +START_CMD="geth" if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/local/bin/geth --continue --" fi if [ "true" == "$RUN_BOOTNODE" ]; then $START_CMD \ + --datadir=~/ethdata \ --nodekeyhex="${BOOTNODE_KEY}" \ --nodiscover \ --ipcdisable \ @@ -74,6 +75,7 @@ else fi $START_CMD \ + --datadir=~/ethdata \ --bootnodes="${ENODE}" \ --allow-insecure-unlock \ --http \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh index 6fa1d8d4..93207d27 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh @@ -19,9 +19,9 @@ http_port=8001 authrpc_port=8551 exec lighthouse \ - --debug-level $DEBUG_LEVEL \ bn \ $SUBSCRIBE_ALL_SUBNETS \ + --debug-level $DEBUG_LEVEL \ --boot-nodes "$ENR" \ --datadir $data_dir \ --testnet-dir $TESTNET_DIR \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh index c7f0dba4..30168f80 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh @@ -21,9 +21,9 @@ while getopts "pd:" flag; do done exec lighthouse \ - --debug-level $DEBUG_LEVEL \ vc \ $BUILDER_PROPOSALS \ + --debug-level $DEBUG_LEVEL \ --validators-dir $DATADIR/node_$NODE_NUMBER/validators \ --secrets-dir $DATADIR/node_$NODE_NUMBER/secrets \ --testnet-dir $TESTNET_DIR \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index 13e137fb..8e80efbb 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -58,6 +58,21 @@ else export JWTSECRET="/opt/testnet/build/cl/jwtsecret" echo -n "$JWT" > $JWTSECRET + # See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script + cleanup() { + echo "Signal received, cleaning up..." + + beacon_node_pid=$(pgrep -o -f 'lighthouse bn') + validator_client_pid=$(pgrep -o -f 'lighthouse vc') + + kill ${beacon_node_pid} + kill ${validator_client_pid} + + wait + echo "Done" + } + trap 'cleanup' SIGINT SIGTERM + ./beacon_node.sh 2>&1 | tee /var/log/lighthouse_bn.log & lpid=$! ./validator_client.sh 2>&1 | tee /var/log/lighthouse_vc.log &