2023-02-19 19:34:14 +03:00
|
|
|
#!/command/with-contenv bash
|
|
|
|
|
# shellcheck shell=bash
|
2023-02-19 20:04:44 +03:00
|
|
|
# Start the go2rtc-healthcheck service
|
2023-02-19 19:34:14 +03:00
|
|
|
|
|
|
|
|
set -o errexit -o nounset -o pipefail
|
|
|
|
|
|
2023-02-19 20:42:58 +03:00
|
|
|
# Logs should be sent to stdout so that s6 can collect them
|
2023-02-19 19:34:14 +03:00
|
|
|
|
2023-02-19 20:04:44 +03:00
|
|
|
# Give some additional time for go2rtc to start before start pinging
|
|
|
|
|
sleep 10s
|
2023-02-19 20:42:58 +03:00
|
|
|
echo "[INFO] Starting go2rtc healthcheck service..."
|
2023-02-19 20:04:44 +03:00
|
|
|
|
2023-02-19 20:42:58 +03:00
|
|
|
while sleep 1s; do
|
2023-02-19 19:34:14 +03:00
|
|
|
# Check if the service is running
|
2023-02-19 20:42:58 +03:00
|
|
|
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..."
|
2023-02-19 19:34:14 +03:00
|
|
|
# We can also use -r instead of -t to send kill signal rather than term
|
2023-02-19 20:42:58 +03:00
|
|
|
s6-svc -t /var/run/service/go2rtc 2>&1
|
2023-02-19 20:04:44 +03:00
|
|
|
# Give some additional time to go2rtc to restart before start pinging again
|
|
|
|
|
sleep 10s
|
2023-02-19 19:34:14 +03:00
|
|
|
fi
|
|
|
|
|
done
|