Skip to content

Commit

Permalink
Ensure dev-node container exits on Ctrl+C
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jul 18, 2024
1 parent e12dfbd commit fa5b1ba
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion scripts/launch-dev-node-with-postgres
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ export POSTGRES_PASSWORD=$ESPRESSO_SEQUENCER_POSTGRES_PASSWORD

export RUST_LOG=${RUST_LOG:-info}

# Function to handle SIGTERM and SIGINT
cleanup() {
echo "Received SIGTERM or SIGINT. Exiting..."
kill -TERM "$postgres_pid" 2>/dev/null
kill -TERM "$dev_node_pid" 2>/dev/null
wait "$postgres_pid"
wait "$dev_node_pid"
exit 0
}

# Trap SIGTERM and SIGINT signals
trap cleanup SIGTERM SIGINT

# Start postgres in the background
docker-entrypoint.sh postgres &
postgres_pid=$!

# Wait (twice) for postgres to be ready
# Postgres can be falsely "ready" once before running init scripts.
Expand All @@ -22,4 +36,9 @@ until pg_isready && sleep 1 && pg_isready; do
done

# Start the dev node
espresso-dev-node
espresso-dev-node &
dev_node_pid=$!

# Wait for child processes to exit
wait "$postgres_pid"
wait "$dev_node_pid"

0 comments on commit fa5b1ba

Please sign in to comment.