2022-05-24 13:51:06 +00:00
|
|
|
#!/usr/bin/env bashio
|
2020-03-22 23:39:37 +00:00
|
|
|
# ==============================================================================
|
|
|
|
# Take down the S6 supervision tree when Home Assistant fails
|
|
|
|
# ==============================================================================
|
2022-06-02 17:49:08 +00:00
|
|
|
declare RESTART_EXIT_CODE=100
|
|
|
|
declare SIGNAL_EXIT_CODE=256
|
|
|
|
declare SIGTERM=15
|
2022-05-24 13:51:06 +00:00
|
|
|
declare APP_EXIT_CODE=${1}
|
2022-06-02 17:49:08 +00:00
|
|
|
declare SIGNAL_NO=${2}
|
2022-05-24 13:51:06 +00:00
|
|
|
declare NEW_EXIT_CODE=
|
2021-09-06 12:37:33 +00:00
|
|
|
|
2022-06-02 17:49:08 +00:00
|
|
|
bashio::log.info "Home Assistant Core finish process exit code ${APP_EXIT_CODE}"
|
2021-09-06 12:37:33 +00:00
|
|
|
|
2022-05-24 13:51:06 +00:00
|
|
|
if [[ ${APP_EXIT_CODE} -eq ${RESTART_EXIT_CODE} ]]; then
|
|
|
|
exit 0
|
|
|
|
elif [[ ${APP_EXIT_CODE} -eq ${SIGNAL_EXIT_CODE} ]]; then
|
2022-06-02 17:49:08 +00:00
|
|
|
bashio::log.info "Home Assistant Core finish process received signal ${SIGNAL_NO}"
|
2020-03-25 09:14:15 +00:00
|
|
|
|
2022-06-02 17:49:08 +00:00
|
|
|
NEW_EXIT_CODE=$((128 + SIGNAL_NO))
|
2022-05-24 13:51:06 +00:00
|
|
|
echo ${NEW_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode
|
|
|
|
|
2022-06-02 17:49:08 +00:00
|
|
|
if [[ ${SIGNAL_NO} -eq ${SIGTERM} ]]; then
|
2022-05-24 13:51:06 +00:00
|
|
|
/run/s6/basedir/bin/halt
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
bashio::log.info "Home Assistant Core service shutdown"
|
|
|
|
|
|
|
|
echo ${APP_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode
|
|
|
|
/run/s6/basedir/bin/halt
|
|
|
|
fi
|