Skip to content

Commit

Permalink
handle script failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed Jul 2, 2024
1 parent 80a9c30 commit 016a9d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ansible/archival-snapshots/resources/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 12 additions & 2 deletions ansible/archival-snapshots/resources/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@ 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=$!

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)
Expand Down Expand Up @@ -98,5 +110,3 @@ while ((LATEST_EPOCH - LAST_EPOCH > 30000)); do

LAST_EPOCH=$NEW_EPOCH
done

kill -KILL $FOREST_NODE_PID

0 comments on commit 016a9d3

Please sign in to comment.