Skip to content

Commit efe8e4c

Browse files
committed
Add signal handling to agbot_start.sh
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]>
1 parent 91401ee commit efe8e4c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

anax-in-container/script/agbot_start.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
# Script to start agbot from inside the container
44

5-
if [ -z "$ANAX_LOG_LEVEL" ]; then
5+
if [ -z "${ANAX_LOG_LEVEL}" ]; then
66
ANAX_LOG_LEVEL=3
77
fi
88

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

13+
# If we receive SIGTERM, forward it to anax to start graceful termination
14+
send_sigterm() {
15+
kill "${ANAX_PID}" 2>/dev/null
16+
}
17+
trap send_sigterm TERM
18+
19+
# Wait for anax termination
20+
wait "${ANAX_PID}"

0 commit comments

Comments
 (0)