From 6fdad74e1414c1d11363e55726de366ef0c57173 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 19 Apr 2023 10:24:41 +0530 Subject: [PATCH] Gracefully shutdown lighthouse boot node --- .../cerc-fixturenet-eth-geth/run-el.sh | 7 ++-- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 37 +++++++++---------- app/data/stacks/fixturenet-eth/README.md | 4 +- 3 files changed, 23 insertions(+), 25 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 8477561a..526c76d7 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 @@ -18,13 +18,14 @@ 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 +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script cleanup() { echo "Signal received, cleaning up..." - # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child) + # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child process) pkill -P ${geth_pid} - sleep 3 - kill ${geth_pid} + sleep 2 + kill $(jobs -p) wait echo "Done" 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 8e80efbb..ec0e9aeb 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 @@ -1,12 +1,25 @@ #!/bin/bash +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script +cleanup() { + echo "Signal received, cleaning up..." + kill $(jobs -p) + + wait + echo "Done" +} +trap 'cleanup' SIGINT SIGTERM + if [ "true" == "$RUN_BOOTNODE" ]; then cd /opt/testnet/build/cl python3 -m http.server 3000 & cd /opt/testnet/cl - ./bootnode.sh 2>&1 | tee /var/log/lighthouse_bootnode.log + ./bootnode.sh 2>&1 | tee /var/log/lighthouse_bootnode.log & + bootnode_pid=$! + + wait $bootnode_pid else while [ 1 -eq 1 ]; do echo "Waiting on geth ..." @@ -58,26 +71,10 @@ 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=$! + beacon_pid=$! ./validator_client.sh 2>&1 | tee /var/log/lighthouse_vc.log & - vpid=$! + validator_pid=$! - wait $lpid $vpid + wait $beacon_pid $validator_pid fi - diff --git a/app/data/stacks/fixturenet-eth/README.md b/app/data/stacks/fixturenet-eth/README.md index 95011127..86404af0 100644 --- a/app/data/stacks/fixturenet-eth/README.md +++ b/app/data/stacks/fixturenet-eth/README.md @@ -117,8 +117,8 @@ Clear volumes created by this stack: ```bash # List all relevant volumes -docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts" +$ docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts" # Remove all the listed volumes -docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts") +$ docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts") ```