Log all services to memory (#4587)

* Log all services to RAM

* Fix tests workdir

* Rotate logs when they reach 10MB and keep only 1 archive

* Gracefully handle shutdown

* Add note about gracetime not working

* Fix logs permission, create fake logs for devcontainer

* Remove empty line

* Update docker/rootfs/etc/services.d/frigate/run

* Fix fake Frigate shebang
This commit is contained in:
Felipe Santos
2022-12-07 10:47:40 -03:00
committed by GitHub
parent 6abc0ce921
commit 2a5ab77637
15 changed files with 101 additions and 14 deletions

View File

@@ -0,0 +1,11 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Prepare the logs folder for s6-log
set -o errexit -o nounset -o pipefail
dirs=(/dev/shm/logs/frigate /dev/shm/logs/go2rtc /dev/shm/logs/nginx)
mkdir -p "${dirs[@]}"
chown nobody:nogroup "${dirs[@]}"
chmod 02755 "${dirs[@]}"

View File

@@ -0,0 +1,16 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Take down the S6 supervision tree when the service exits
set -o errexit -o nounset -o pipefail
# Prepare exit code
if [[ "${1}" -eq 256 ]]; then
exit_code="$((128 + ${2}))"
else
exit_code="${1}"
fi
# Make the container exit with the same exit code as the service
echo "${exit_code}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt

View File

@@ -0,0 +1,4 @@
#!/command/with-contenv bash
# shellcheck shell=bash
exec logutil-service /dev/shm/logs/frigate

View File

@@ -0,0 +1,11 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Start the Frigate service
set -o errexit -o nounset -o pipefail
cd /opt/frigate
# Replace the bash process with the Frigate process, redirecting stderr to stdout
exec 2>&1
exec python3 -u -m frigate

View File

@@ -1,6 +1,7 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Take down the S6 supervision tree when the process fails
# Take down the S6 supervision tree when the service fails, or restart it
# otherwise
if [[ "${1}" -ne 0 && "${1}" -ne 256 ]]; then
exec /run/s6/basedir/bin/halt

View File

@@ -0,0 +1,4 @@
#!/command/with-contenv bash
# shellcheck shell=bash
exec logutil-service /dev/shm/logs/go2rtc

View File

@@ -1,8 +1,8 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Start the go2rtc service
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3945021
set -euo pipefail
set -o errexit -o nounset -o pipefail
if [[ -f "/config/frigate-go2rtc.yaml" ]]; then
config_path="/config/frigate-go2rtc.yaml"
@@ -10,4 +10,6 @@ else
config_path="/usr/local/go2rtc/go2rtc.yaml"
fi
# Replace the bash process with the go2rtc process, redirecting stderr to stdout
exec 2>&1
exec go2rtc -config="${config_path}"

View File

@@ -1,6 +1,7 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Take down the S6 supervision tree when the process fails
# Take down the S6 supervision tree when the service fails, or restart it
# otherwise
if [[ "${1}" -ne 0 && "${1}" -ne 256 ]]; then
exec /run/s6/basedir/bin/halt

View File

@@ -0,0 +1,4 @@
#!/command/with-contenv bash
# shellcheck shell=bash
exec logutil-service /dev/shm/logs/nginx

View File

@@ -1,4 +1,7 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# Start the NGINX service
# Replace the bash process with the NGINX process, redirecting stderr to stdout
exec 2>&1
exec nginx

View File

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

View File

@@ -2,7 +2,7 @@ daemon off;
user root;
worker_processes 1;
error_log /usr/local/nginx/logs/error.log warn;
error_log /dev/stdout warn;
pid /var/run/nginx.pid;
events {
@@ -17,7 +17,7 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log main;
access_log /dev/stdout main;
sendfile on;