mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-12-19 19:06:16 +01:00
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:
parent
6abc0ce921
commit
2a5ab77637
26
Dockerfile
26
Dockerfile
@ -155,10 +155,6 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility"
|
|||||||
|
|
||||||
ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:${PATH}"
|
ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:${PATH}"
|
||||||
|
|
||||||
# TODO: remove after a new verion of s6-overlay is released. See:
|
|
||||||
# https://github.com/just-containers/s6-overlay/issues/460#issuecomment-1327127006
|
|
||||||
ENV S6_SERVICES_READYTIME=50
|
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
|
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
|
||||||
/deps/install_deps.sh
|
/deps/install_deps.sh
|
||||||
@ -175,11 +171,31 @@ EXPOSE 1935
|
|||||||
EXPOSE 8554
|
EXPOSE 8554
|
||||||
EXPOSE 8555
|
EXPOSE 8555
|
||||||
|
|
||||||
|
# Fails if cont-init.d fails
|
||||||
|
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
|
||||||
|
# Wait indefinitely for cont-init.d to finish before starting services
|
||||||
|
ENV S6_CMD_WAIT_FOR_SERVICES=1
|
||||||
|
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
|
||||||
|
# Give services (including Frigate) 30 seconds to stop before killing them
|
||||||
|
# But this is not working currently because of:
|
||||||
|
# https://github.com/just-containers/s6-overlay/issues/503
|
||||||
|
ENV S6_SERVICES_GRACETIME=30000
|
||||||
|
# Configure logging to prepend timestamps, log to stdout, keep 1 archive and rotate on 10MB
|
||||||
|
ENV S6_LOGGING_SCRIPT="T 1 n1 s10000000 T"
|
||||||
|
# TODO: remove after a new version of s6-overlay is released. See:
|
||||||
|
# https://github.com/just-containers/s6-overlay/issues/460#issuecomment-1327127006
|
||||||
|
ENV S6_SERVICES_READYTIME=50
|
||||||
|
|
||||||
ENTRYPOINT ["/init"]
|
ENTRYPOINT ["/init"]
|
||||||
|
CMD []
|
||||||
|
|
||||||
# Frigate deps with Node.js and NPM for devcontainer
|
# Frigate deps with Node.js and NPM for devcontainer
|
||||||
FROM deps AS devcontainer
|
FROM deps AS devcontainer
|
||||||
|
|
||||||
|
# Do not start the actual Frigate service on devcontainer as it will be started by VSCode
|
||||||
|
# But start a fake service for simulating the logs
|
||||||
|
COPY docker/fake_frigate_run /etc/services.d/frigate/run
|
||||||
|
|
||||||
# Install Node 16
|
# Install Node 16
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install wget -y \
|
&& apt-get install wget -y \
|
||||||
@ -224,5 +240,3 @@ FROM deps
|
|||||||
|
|
||||||
WORKDIR /opt/frigate/
|
WORKDIR /opt/frigate/
|
||||||
COPY --from=rootfs / /
|
COPY --from=rootfs / /
|
||||||
|
|
||||||
CMD ["with-contenv", "python3", "-u", "-m", "frigate"]
|
|
||||||
|
7
Makefile
7
Makefile
@ -30,8 +30,11 @@ build: version amd64 arm64 armv7
|
|||||||
push: build
|
push: build
|
||||||
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) .
|
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) .
|
||||||
|
|
||||||
|
run: local
|
||||||
|
docker run --rm --publish=5000:5000 --volume=${PWD}/config/config.yml:/config/config.yml frigate:latest
|
||||||
|
|
||||||
run_tests: local
|
run_tests: local
|
||||||
docker run --rm --entrypoint=python3 frigate:latest -u -m unittest
|
docker run --rm --workdir=/opt/frigate --entrypoint= frigate:latest python3 -u -m unittest
|
||||||
docker run --rm --entrypoint=python3 frigate:latest -u -m mypy --config-file frigate/mypy.ini frigate
|
docker run --rm --workdir=/opt/frigate --entrypoint= frigate:latest python3 -u -m mypy --config-file frigate/mypy.ini frigate
|
||||||
|
|
||||||
.PHONY: run_tests
|
.PHONY: run_tests
|
||||||
|
8
docker/fake_frigate_run
Executable file
8
docker/fake_frigate_run
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
# Start the fake Frigate service
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
echo "The fake Frigate service is running..."
|
||||||
|
sleep 5s
|
||||||
|
done
|
11
docker/rootfs/etc/cont-init.d/prepare-logs.sh
Executable file
11
docker/rootfs/etc/cont-init.d/prepare-logs.sh
Executable 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[@]}"
|
16
docker/rootfs/etc/services.d/frigate/finish
Executable file
16
docker/rootfs/etc/services.d/frigate/finish
Executable 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
|
4
docker/rootfs/etc/services.d/frigate/log/run
Executable file
4
docker/rootfs/etc/services.d/frigate/log/run
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
exec logutil-service /dev/shm/logs/frigate
|
11
docker/rootfs/etc/services.d/frigate/run
Executable file
11
docker/rootfs/etc/services.d/frigate/run
Executable 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
|
@ -1,6 +1,7 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
# shellcheck shell=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
|
if [[ "${1}" -ne 0 && "${1}" -ne 256 ]]; then
|
||||||
exec /run/s6/basedir/bin/halt
|
exec /run/s6/basedir/bin/halt
|
||||||
|
4
docker/rootfs/etc/services.d/go2rtc/log/run
Executable file
4
docker/rootfs/etc/services.d/go2rtc/log/run
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
exec logutil-service /dev/shm/logs/go2rtc
|
@ -1,8 +1,8 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
# Start the go2rtc service
|
||||||
|
|
||||||
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3945021
|
set -o errexit -o nounset -o pipefail
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if [[ -f "/config/frigate-go2rtc.yaml" ]]; then
|
if [[ -f "/config/frigate-go2rtc.yaml" ]]; then
|
||||||
config_path="/config/frigate-go2rtc.yaml"
|
config_path="/config/frigate-go2rtc.yaml"
|
||||||
@ -10,4 +10,6 @@ else
|
|||||||
config_path="/usr/local/go2rtc/go2rtc.yaml"
|
config_path="/usr/local/go2rtc/go2rtc.yaml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Replace the bash process with the go2rtc process, redirecting stderr to stdout
|
||||||
|
exec 2>&1
|
||||||
exec go2rtc -config="${config_path}"
|
exec go2rtc -config="${config_path}"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
# shellcheck shell=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
|
if [[ "${1}" -ne 0 && "${1}" -ne 256 ]]; then
|
||||||
exec /run/s6/basedir/bin/halt
|
exec /run/s6/basedir/bin/halt
|
||||||
|
4
docker/rootfs/etc/services.d/nginx/log/run
Executable file
4
docker/rootfs/etc/services.d/nginx/log/run
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
exec logutil-service /dev/shm/logs/nginx
|
@ -1,4 +1,7 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
# shellcheck shell=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
|
exec nginx
|
||||||
|
5
docker/rootfs/usr/local/bin/frigate
Normal file
5
docker/rootfs/usr/local/bin/frigate
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
exec 2>&1
|
||||||
|
exec python3 -u -m frigate "${@}"
|
@ -2,7 +2,7 @@ daemon off;
|
|||||||
user root;
|
user root;
|
||||||
worker_processes 1;
|
worker_processes 1;
|
||||||
|
|
||||||
error_log /usr/local/nginx/logs/error.log warn;
|
error_log /dev/stdout warn;
|
||||||
pid /var/run/nginx.pid;
|
pid /var/run/nginx.pid;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
@ -17,7 +17,7 @@ http {
|
|||||||
'$status $body_bytes_sent "$http_referer" '
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
|
||||||
access_log /usr/local/nginx/logs/access.log main;
|
access_log /dev/stdout main;
|
||||||
|
|
||||||
sendfile on;
|
sendfile on;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user