Skip to content

Commit

Permalink
Add signal handling to agbot/css_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.

The same happens for the ccs-api.

This change adds proper SIGTERM handling to agbot_start.sh and
css_start.sh.

Signed-off-by: Leonardo Bergesio <[email protected]>
  • Loading branch information
lbergesio authored and LiilyZhang committed Apr 17, 2024
1 parent c89b9aa commit d851295
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 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}"
12 changes: 11 additions & 1 deletion css/script/css_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#!/bin/bash

/usr/bin/envsubst < /etc/edge-sync-service/sync.conf.tmpl > /etc/edge-sync-service/sync.conf
/home/cssuser/cloud-sync-service
/home/cssuser/cloud-sync-service &
CSS_PID=$!

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

# Wait for css termination
wait "${CSS_PID}"

0 comments on commit d851295

Please sign in to comment.