Skip to content

Commit

Permalink
Shutdown the container on abnormal signals (home-assistant#55660)
Browse files Browse the repository at this point in the history
So far the finish script exits whenever the service terminated by a
signal (indicated by 256 as first argument). This is the intended
behavior when SIGTERM is being sent: SIGTERM is used on regular shutdown
through the supervisor. We don't want the finish script to shutdown
itself while being taken down by the supervisor already.

However, every other signal which lead to a process exit likely means
trouble: SIGSEGV, SIGILL, etc. In those cases we want the container to
exit. The Supervisor (or restart policy of Docker in the container case)
will take care of restarting if appropriate.
  • Loading branch information
agners authored Sep 6, 2021
1 parent 05abf14 commit df928c8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rootfs/etc/services.d/home-assistant/finish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
# ==============================================================================
# Take down the S6 supervision tree when Home Assistant fails
# ==============================================================================
if { s6-test ${1} -ne 100 }
if { s6-test ${1} -ne 256 }
define HA_RESTART_EXIT_CODE 100
define SIGNAL_EXIT_CODE 256
define SIGTERM 15

foreground { s6-echo "[finish] process exit code ${1}" }

if { s6-test ${1} -ne ${HA_RESTART_EXIT_CODE} }
ifelse { s6-test ${1} -eq ${SIGNAL_EXIT_CODE} } {
# Process terminated by a signal
define signal ${2}
foreground { s6-echo "[finish] process received signal ${signal}" }
if { s6-test ${signal} -ne ${SIGTERM} }
s6-svscanctl -t /var/run/s6/services
}

s6-svscanctl -t /var/run/s6/services

0 comments on commit df928c8

Please sign in to comment.