From 1d15eaae26e6797142c56cc2d2dc4eb95897d68e Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 17 Jan 2023 12:58:34 -0300 Subject: [PATCH] Restart the whole container if either Frigate or go2rtc fails --- docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish | 13 ++++++++----- docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run | 3 +++ docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish | 11 +++++++---- docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run | 8 ++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish b/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish index 14f63ae83..df31d41bb 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish @@ -9,7 +9,7 @@ exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode) readonly exit_code_container readonly exit_code_service="${1}" 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 @@ -17,12 +17,15 @@ if [[ "${exit_code_service}" -eq 256 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode fi - if [[ "${exit_code_signal}" -eq 15 ]]; then - exec /run/s6/basedir/bin/halt - fi elif [[ "${exit_code_service}" -ne 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode 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 + +exec /run/s6/basedir/bin/halt diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run b/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run index c543ff0ff..905f4b670 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run @@ -4,6 +4,9 @@ set -o errexit -o nounset -o pipefail +# Tell S6-Overlay not to restart this service +s6-svc -O . + cd /opt/frigate # Replace the bash process with the Frigate process, redirecting stderr to stdout diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish index 2e95e74fc..9ebb6375e 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish @@ -17,12 +17,15 @@ if [[ "${exit_code_service}" -eq 256 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode fi - if [[ "${exit_code_signal}" -eq 15 ]]; then - exec /run/s6/basedir/bin/halt - fi elif [[ "${exit_code_service}" -ne 0 ]]; then if [[ "${exit_code_container}" -eq 0 ]]; then echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode 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 + +exec /run/s6/basedir/bin/halt diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run index db5c2a869..b9d03962f 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run @@ -4,8 +4,16 @@ 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) # Replace the bash process with the go2rtc process, redirecting stderr to stdout exec 2>&1 + +echo starting go2rtc +sleep 20s +exit 0 + exec go2rtc -config="${raw_config}"