Fix healthcheck not starting

This commit is contained in:
Felipe Santos 2023-02-19 14:42:58 -03:00
parent 46a9d47923
commit 52a2c1add2
7 changed files with 20 additions and 19 deletions

View File

@ -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

View File

@ -0,0 +1 @@
go2rtc-log

View File

@ -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

View File

@ -1 +1,2 @@
go2rtc
go2rtc-healthcheck

View File

@ -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

View File

@ -1,5 +0,0 @@
#!/command/with-contenv bash
# shellcheck shell=bash
exec 2>&1
exec python3 -u -m frigate "${@}"

View File

@ -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