From 52a2c1add2c7ddfa3da04f890cb26191951d3609 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 19 Feb 2023 14:42:58 -0300 Subject: [PATCH] Fix healthcheck not starting --- docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run | 6 ++++-- .../s6-rc.d/go2rtc-healthcheck/producer-for | 1 + .../etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run | 11 ++++++----- .../etc/s6-overlay/s6-rc.d/go2rtc-log/consumer-for | 1 + docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run | 14 ++++++++------ docker/rootfs/usr/local/bin/frigate | 5 ----- docker/rootfs/usr/local/go2rtc/create_config.py | 1 - 7 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/producer-for delete mode 100644 docker/rootfs/usr/local/bin/frigate 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 1adf1a0cb..562081fc5 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/run @@ -4,12 +4,14 @@ set -o errexit -o nounset -o pipefail +# Logs should be sent to stdout so that s6 can collect them + # Tell S6-Overlay not to restart this service s6-svc -O . -echo "[INFO] Starting Frigate..." >&2 +echo "[INFO] Starting Frigate..." -cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate" >&2 +cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate" # Replace the bash process with the Frigate process, redirecting stderr to stdout exec 2>&1 diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/producer-for b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/producer-for new file mode 100644 index 000000000..20fbc45f8 --- /dev/null +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/producer-for @@ -0,0 +1 @@ +go2rtc-log diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run index d48ac9db5..42a01b1cf 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run @@ -4,17 +4,18 @@ set -o errexit -o nounset -o pipefail -echo "[INFO] Starting go2rtc healthcheck service..." >&2 +# Logs should be sent to stdout so that s6 can collect them # Give some additional time for go2rtc to start before start pinging sleep 10s +echo "[INFO] Starting go2rtc healthcheck service..." -while sleep 1m; do +while sleep 1s; do # Check if the service is running - if ! timeout 10s curl -fsSL http://127.0.0.1:1984/api/streams >/dev/null; then - echo "[ERROR] The go2rtc service is not responding to ping, restarting..." >&2 + if ! timeout 10s curl -fsSL -o /dev/null http://127.0.0.1:1984/api/streams 2>&1; then + echo "[ERROR] The go2rtc service is not responding to ping, restarting..." # We can also use -r instead of -t to send kill signal rather than term - s6-svc -t /var/run/service/go2rtc + s6-svc -t /var/run/service/go2rtc 2>&1 # Give some additional time to go2rtc to restart before start pinging again sleep 10s fi diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/consumer-for b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/consumer-for index 02b16a879..bdd482e42 100644 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/consumer-for +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/consumer-for @@ -1 +1,2 @@ go2rtc +go2rtc-healthcheck 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 40110808f..1f46194a3 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run @@ -4,6 +4,8 @@ set -o errexit -o nounset -o pipefail +# Logs should be sent to stdout so that s6 can collect them + function get_ip_and_port_from_supervisor() { local ip_address # Example: 192.168.1.10/24 @@ -16,9 +18,9 @@ function get_ip_and_port_from_supervisor() { jq --exit-status --raw-output '.data.ipv4.address[0]' ) && [[ "${ip_address}" =~ ${ip_regex} ]]; then ip_address="${BASH_REMATCH[1]}" - echo "[INFO] Got IP address from supervisor: ${ip_address}" >&2 + echo "[INFO] Got IP address from supervisor: ${ip_address}" else - echo "[WARN] Failed to get IP address from supervisor" >&2 + echo "[WARN] Failed to get IP address from supervisor" return 0 fi @@ -32,9 +34,9 @@ function get_ip_and_port_from_supervisor() { jq --exit-status --raw-output '.data.network["8555/tcp"]' ) && [[ "${webrtc_port}" =~ ${port_regex} ]]; then webrtc_port="${BASH_REMATCH[1]}" - echo "[INFO] Got WebRTC port from supervisor: ${webrtc_port}" >&2 + echo "[INFO] Got WebRTC port from supervisor: ${webrtc_port}" else - echo "[WARN] Failed to get WebRTC port from supervisor" >&2 + echo "[WARN] Failed to get WebRTC port from supervisor" return 0 fi @@ -42,7 +44,7 @@ function get_ip_and_port_from_supervisor() { } if [[ ! -f "/dev/shm/go2rtc.yaml" ]]; then - echo "[INFO] Preparing go2rtc config..." >&2 + echo "[INFO] Preparing go2rtc config..." if [[ -n "${SUPERVISOR_TOKEN:-}" ]]; then # Running as a Home Assistant add-on, infer the IP address and port @@ -52,7 +54,7 @@ if [[ ! -f "/dev/shm/go2rtc.yaml" ]]; then python3 /usr/local/go2rtc/create_config.py fi -echo "[INFO] Starting go2rtc..." >&2 +echo "[INFO] Starting go2rtc..." # Replace the bash process with the go2rtc process, redirecting stderr to stdout exec 2>&1 diff --git a/docker/rootfs/usr/local/bin/frigate b/docker/rootfs/usr/local/bin/frigate deleted file mode 100644 index 7e431b11c..000000000 --- a/docker/rootfs/usr/local/bin/frigate +++ /dev/null @@ -1,5 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -exec 2>&1 -exec python3 -u -m frigate "${@}" diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py index dfe6a5f9b..d034e044b 100644 --- a/docker/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/rootfs/usr/local/go2rtc/create_config.py @@ -51,7 +51,6 @@ if not go2rtc_config.get("webrtc", {}).get("candidates", []): else: print( "[INFO] Not injecting WebRTC candidates into go2rtc config as it has been set manually", - file=sys.stderr, ) # sets default RTSP response to be equivalent to ?video=h264,h265&audio=aac