Skip to content

Commit

Permalink
Add signal handling to agbot_start.sh
Browse files Browse the repository at this point in the history
When run in a container anax is run via a shell script that does not
handle SIGTERM and hence when the container is stopped this signal does
not arrive to the binary for graceful exit. A consequence of this is
when run via docker compose up, docker compose down will have to wait
until the timeout in order to kill the process.

This change adds this to agbot_start.sh

Signed-off-by: Leonardo Bergesio <[email protected]>
  • Loading branch information
lbergesio committed Apr 16, 2024
1 parent 91401ee commit efe8e4c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions anax-in-container/script/agbot_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

# Script to start agbot from inside the container

if [ -z "$ANAX_LOG_LEVEL" ]; then
if [ -z "${ANAX_LOG_LEVEL}" ]; then
ANAX_LOG_LEVEL=3
fi

/usr/bin/envsubst < /etc/horizon/anax.json.tmpl > /etc/horizon/anax.json
/usr/horizon/bin/anax -v $ANAX_LOG_LEVEL -logtostderr -config /etc/horizon/anax.json
/usr/horizon/bin/anax -v "${ANAX_LOG_LEVEL}" -logtostderr -config /etc/horizon/anax.json &
ANAX_PID=$!

# If we receive SIGTERM, forward it to anax to start graceful termination
send_sigterm() {
kill "${ANAX_PID}" 2>/dev/null
}
trap send_sigterm TERM

# Wait for anax termination
wait "${ANAX_PID}"

0 comments on commit efe8e4c

Please sign in to comment.