This commit is contained in:
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# Graceful shutdown of the compose api service: SIGTERM -> exit 0 within 10s
|
||||
# (not SIGKILL 137), then the service is started again. Volumes are untouched.
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
CID=$(docker compose ps -q api)
|
||||
[ -n "$CID" ] || { echo "FAIL: api is not running"; exit 1; }
|
||||
|
||||
START=$(date +%s)
|
||||
docker compose stop api >/dev/null 2>&1
|
||||
ELAPSED=$(( $(date +%s) - START ))
|
||||
EXIT_CODE=$(docker inspect -f '{{.State.ExitCode}}' "$CID")
|
||||
echo "api stopped in ${ELAPSED}s, exit code ${EXIT_CODE} (0 = graceful, 137 = SIGKILL)"
|
||||
docker compose logs --since 30s api 2>&1 | grep -q "Application shutdown complete" || { echo "FAIL: no graceful shutdown line"; exit 1; }
|
||||
[ "$ELAPSED" -le 10 ] && [ "$EXIT_CODE" -eq 0 ] || { docker compose up -d --wait api; echo "FAIL: not graceful"; exit 1; }
|
||||
|
||||
docker compose up -d --no-build --wait api >/dev/null 2>&1
|
||||
echo "PASS: graceful SIGTERM shutdown, api restarted"
|
||||
Reference in New Issue
Block a user