From 016a9d3d0239b409d08d378c9e4f1497f7160c58 Mon Sep 17 00:00:00 2001 From: sudo-shashank Date: Tue, 2 Jul 2024 11:20:24 +0530 Subject: [PATCH] handle script failure --- ansible/archival-snapshots/resources/init.sh | 13 +++++++++++++ ansible/archival-snapshots/resources/main.sh | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ansible/archival-snapshots/resources/init.sh b/ansible/archival-snapshots/resources/init.sh index 051e642d0..850c81a4a 100755 --- a/ansible/archival-snapshots/resources/init.sh +++ b/ansible/archival-snapshots/resources/init.sh @@ -31,3 +31,16 @@ fi # Trigger main script ./main.sh + +EXIT_STATUS=$? + +# Notify on slack channel +if [ "$EXIT_STATUS" -eq 0 ]; then + echo "Script executed successfully" + ruby notify.rb success +else + echo "Script execution failed" + ruby notify.rb failure +fi + +exit "$EXIT_STATUS" \ No newline at end of file diff --git a/ansible/archival-snapshots/resources/main.sh b/ansible/archival-snapshots/resources/main.sh index 0394ac6cc..b23c84477 100755 --- a/ansible/archival-snapshots/resources/main.sh +++ b/ansible/archival-snapshots/resources/main.sh @@ -28,6 +28,9 @@ else echo "$LAST_FULL_SNAPSHOT_PATH snapshot exists." fi +# Clean forest db +$FOREST_TOOL db destroy --force + echo "Starting forest daemon" nohup $FOREST --no-gc --config ./config.toml --save-token ./admin_token --rpc-address 127.0.0.1:3456 --metrics-address 127.0.0.1:5000 --import-snapshot "$LAST_FULL_SNAPSHOT_PATH" > forest.log 2>&1 & FOREST_NODE_PID=$! @@ -35,6 +38,15 @@ FOREST_NODE_PID=$! sleep 30 echo "Forest process started with PID: $FOREST_NODE_PID" +# Function to kill Forest daemon +function kill_forest_daemon { + echo "Killing Forest daemon with PID: $FOREST_NODE_PID" + kill -KILL $FOREST_NODE_PID +} + +# Set trap to kill Forest daemon on script exit or error +trap kill_forest_daemon EXIT + # Set required env variables function set_fullnode_api_info { ADMIN_TOKEN=$(cat admin_token) @@ -98,5 +110,3 @@ while ((LATEST_EPOCH - LAST_EPOCH > 30000)); do LAST_EPOCH=$NEW_EPOCH done - -kill -KILL $FOREST_NODE_PID