Restart the whole container if either Frigate or go2rtc fails

This commit is contained in:
Felipe Santos 2023-01-17 12:58:34 -03:00
parent 473c8d30c8
commit 1d15eaae26
4 changed files with 26 additions and 9 deletions

View File

@ -9,7 +9,7 @@ exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode)
readonly exit_code_container readonly exit_code_container
readonly exit_code_service="${1}" readonly exit_code_service="${1}"
readonly exit_code_signal="${2}" readonly exit_code_signal="${2}"
readonly service="Frigate" readonly service="frigate"
echo "Service ${service} exited with code ${exit_code_service} (by signal ${exit_code_signal})" >&2 echo "Service ${service} exited with code ${exit_code_service} (by signal ${exit_code_signal})" >&2
@ -17,12 +17,15 @@ if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi fi
if [[ "${exit_code_signal}" -eq 15 ]]; then
exec /run/s6/basedir/bin/halt
fi
elif [[ "${exit_code_service}" -ne 0 ]]; then elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi fi
exec /run/s6/basedir/bin/halt else
# If the service exited with code 0, then we want to set the container exit code to 1
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "1" > /run/s6-linux-init-container-results/exitcode
fi
fi fi
exec /run/s6/basedir/bin/halt

View File

@ -4,6 +4,9 @@
set -o errexit -o nounset -o pipefail set -o errexit -o nounset -o pipefail
# Tell S6-Overlay not to restart this service
s6-svc -O .
cd /opt/frigate cd /opt/frigate
# Replace the bash process with the Frigate process, redirecting stderr to stdout # Replace the bash process with the Frigate process, redirecting stderr to stdout

View File

@ -17,12 +17,15 @@ if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi fi
if [[ "${exit_code_signal}" -eq 15 ]]; then
exec /run/s6/basedir/bin/halt
fi
elif [[ "${exit_code_service}" -ne 0 ]]; then elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi fi
exec /run/s6/basedir/bin/halt else
# If the service exited with code 0, then we want to set the container exit code to 1 if it's 0
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "1" > /run/s6-linux-init-container-results/exitcode
fi
fi fi
exec /run/s6/basedir/bin/halt

View File

@ -4,8 +4,16 @@
set -o errexit -o nounset -o pipefail set -o errexit -o nounset -o pipefail
# Tell S6-Overlay not to restart this service
s6-svc -O .
raw_config=$(python3 /usr/local/go2rtc/create_config.py) raw_config=$(python3 /usr/local/go2rtc/create_config.py)
# Replace the bash process with the go2rtc process, redirecting stderr to stdout # Replace the bash process with the go2rtc process, redirecting stderr to stdout
exec 2>&1 exec 2>&1
echo starting go2rtc
sleep 20s
exit 0
exec go2rtc -config="${raw_config}" exec go2rtc -config="${raw_config}"