mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 17:55:21 +03:00
Gracefully handle shutdown
This commit is contained in:
parent
7c98aa9f61
commit
7e222642c9
24
Dockerfile
24
Dockerfile
@ -155,17 +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}"
|
||||||
|
|
||||||
# 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
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# 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
|
||||||
@ -182,6 +171,19 @@ 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
|
||||||
|
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 []
|
CMD []
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
# Prepare the logs folder for s6-log
|
||||||
|
|
||||||
set -euo pipefail
|
set -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
mkdir -p /dev/shm/logs
|
mkdir -p /dev/shm/logs
|
||||||
chown nobody:nogroup /dev/shm/logs
|
chown nobody:nogroup /dev/shm/logs
|
||||||
|
|||||||
@ -1,7 +1,16 @@
|
|||||||
#!/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 exits
|
||||||
|
|
||||||
if [[ "${1}" -ne 0 && "${1}" -ne 256 ]]; then
|
set -o errexit -o nounset -o pipefail
|
||||||
exec /run/s6/basedir/bin/halt
|
|
||||||
|
# Prepare exit code
|
||||||
|
if [[ "${1}" -eq 256 ]]; then
|
||||||
|
exit_code="$((128 + ${2}))"
|
||||||
|
else
|
||||||
|
exit_code="${1}"
|
||||||
fi
|
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
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
#!/command/with-contenv bash
|
#!/bin/bash
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
# Start the Frigate service
|
||||||
|
|
||||||
set -euo pipefail
|
set -o errexit -o nounset -o pipefail -o xtrace
|
||||||
|
|
||||||
cd /opt/frigate
|
cd /opt/frigate
|
||||||
|
|
||||||
|
# Replace the bash process with the Frigate process, redirecting stderr to stdout
|
||||||
exec 2>&1
|
exec 2>&1
|
||||||
exec python3 -u -m frigate
|
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
|
||||||
|
|||||||
@ -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,5 +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 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
|
||||||
|
|||||||
@ -1,5 +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 2>&1
|
||||||
exec nginx
|
exec nginx
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user