mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Refactor s6 scripts to the new format (#5135)
* Refator s6 scripts to the new format * Remove unneeded workaround * Migrate logging to new s6 format * Remove more unnecessary s6 variables * Fix prepare-log and when go2rtc is not present in config * Restart the whole container if either Frigate or go2rtc fails * D * Fix service name in finish * Fix nginx finish comment * Restart improvements * Fix devcontainer * Fix format * Update Dockerfile Co-authored-by: Felipe Santos <felipecassiors@gmail.com> Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
This commit is contained in:
parent
89513e469a
commit
02df2a8bbd
16
Dockerfile
16
Dockerfile
@ -192,22 +192,10 @@ RUN ldconfig
|
||||
EXPOSE 5000
|
||||
EXPOSE 1935
|
||||
EXPOSE 8554
|
||||
EXPOSE 8555
|
||||
EXPOSE 8555/tcp 8555/udp
|
||||
|
||||
# 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 0 archives and rotate on 10MB
|
||||
ENV S6_LOGGING_SCRIPT="T 1 n0 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"]
|
||||
CMD []
|
||||
@ -217,7 +205,7 @@ 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
|
||||
COPY docker/fake_frigate_run /etc/s6-overlay/s6-rc.d/frigate/run
|
||||
|
||||
# Install Node 16
|
||||
RUN apt-get update \
|
||||
|
@ -0,0 +1 @@
|
||||
frigate
|
@ -0,0 +1 @@
|
||||
frigate-pipeline
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate-log/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate-log/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
30
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish
Executable file
30
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/finish
Executable file
@ -0,0 +1,30 @@
|
||||
#!/command/with-contenv bash
|
||||
# shellcheck shell=bash
|
||||
# Take down the S6 supervision tree when the service exits
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
declare exit_code_container
|
||||
exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode)
|
||||
readonly exit_code_container
|
||||
readonly exit_code_service="${1}"
|
||||
readonly exit_code_signal="${2}"
|
||||
readonly service="Frigate"
|
||||
|
||||
echo "Service ${service} exited with code ${exit_code_service} (by signal ${exit_code_signal})" >&2
|
||||
|
||||
if [[ "${exit_code_service}" -eq 256 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
elif [[ "${exit_code_service}" -ne 0 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
else
|
||||
# Exit code 0 is expected when Frigate is restarted by the user. In this case,
|
||||
# we create a signal for the go2rtc finish script to tolerate the restart.
|
||||
touch /dev/shm/restarting-frigate
|
||||
fi
|
||||
|
||||
exec /run/s6/basedir/bin/halt
|
@ -0,0 +1 @@
|
||||
frigate-log
|
@ -4,6 +4,9 @@
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
# Tell S6-Overlay not to restart this service
|
||||
s6-svc -O .
|
||||
|
||||
cd /opt/frigate
|
||||
|
||||
# Replace the bash process with the Frigate process, redirecting stderr to stdout
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/frigate/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
@ -0,0 +1 @@
|
||||
go2rtc
|
@ -0,0 +1 @@
|
||||
go2rtc-pipeline
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-log/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
32
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish
Executable file
32
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/finish
Executable file
@ -0,0 +1,32 @@
|
||||
#!/command/with-contenv bash
|
||||
# shellcheck shell=bash
|
||||
# Take down the S6 supervision tree when the service exits
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
declare exit_code_container
|
||||
exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode)
|
||||
readonly exit_code_container
|
||||
readonly exit_code_service="${1}"
|
||||
readonly exit_code_signal="${2}"
|
||||
readonly service="go2rtc"
|
||||
|
||||
echo "Service ${service} exited with code ${exit_code_service} (by signal ${exit_code_signal})" >&2
|
||||
|
||||
if [[ "${exit_code_service}" -eq 256 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
elif [[ "${exit_code_service}" -ne 0 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
else
|
||||
# go2rtc is not supposed to exit, so even when it exits with 0 we make the
|
||||
# container with 1. We only tolerate it when Frigate is restarting.
|
||||
if [[ "${exit_code_container}" -eq 0 && ! -f /dev/shm/restarting-frigate ]]; then
|
||||
echo "1" > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
fi
|
||||
|
||||
exec /run/s6/basedir/bin/halt
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/producer-for
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/producer-for
Normal file
@ -0,0 +1 @@
|
||||
go2rtc-log
|
@ -4,6 +4,9 @@
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
# Tell S6-Overlay not to restart this service
|
||||
s6-svc -O .
|
||||
|
||||
raw_config=$(python3 /usr/local/go2rtc/create_config.py)
|
||||
|
||||
# Replace the bash process with the go2rtc process, redirecting stderr to stdout
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/log-prepare/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/log-prepare/type
Normal file
@ -0,0 +1 @@
|
||||
oneshot
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/log-prepare/up
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/log-prepare/up
Normal file
@ -0,0 +1 @@
|
||||
/etc/s6-overlay/s6-rc.d/log-prepare/run
|
@ -0,0 +1 @@
|
||||
nginx
|
@ -0,0 +1 @@
|
||||
nginx-pipeline
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx-log/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx-log/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
28
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/finish
Executable file
28
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/finish
Executable file
@ -0,0 +1,28 @@
|
||||
#!/command/with-contenv bash
|
||||
# shellcheck shell=bash
|
||||
# Take down the S6 supervision tree when the service fails
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
declare exit_code_container
|
||||
exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode)
|
||||
readonly exit_code_container
|
||||
readonly exit_code_service="${1}"
|
||||
readonly exit_code_signal="${2}"
|
||||
readonly service="NGINX"
|
||||
|
||||
echo "Service ${service} exited with code ${exit_code_service} (by signal ${exit_code_signal})" >&2
|
||||
|
||||
if [[ "${exit_code_service}" -eq 256 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
if [[ "${exit_code_signal}" -eq 15 ]]; then
|
||||
exec /run/s6/basedir/bin/halt
|
||||
fi
|
||||
elif [[ "${exit_code_service}" -ne 0 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
exec /run/s6/basedir/bin/halt
|
||||
fi
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/producer-for
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/producer-for
Normal file
@ -0,0 +1 @@
|
||||
nginx-log
|
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/type
Normal file
1
docker/rootfs/etc/s6-overlay/s6-rc.d/nginx/type
Normal file
@ -0,0 +1 @@
|
||||
longrun
|
@ -1,16 +0,0 @@
|
||||
#!/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
|
@ -1,8 +0,0 @@
|
||||
#!/command/with-contenv bash
|
||||
# shellcheck shell=bash
|
||||
# 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
|
||||
fi
|
@ -1,8 +0,0 @@
|
||||
#!/command/with-contenv bash
|
||||
# shellcheck shell=bash
|
||||
# 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
|
||||
fi
|
@ -769,7 +769,10 @@ def config_save():
|
||||
logging.error(f"Error restarting Frigate: {e}")
|
||||
return "Config successfully saved, unable to restart Frigate", 200
|
||||
|
||||
return "Config successfully saved, restarting...", 200
|
||||
return (
|
||||
"Config successfully saved, restarting (this can take up to one minute)...",
|
||||
200,
|
||||
)
|
||||
else:
|
||||
return "Config successfully saved.", 200
|
||||
|
||||
|
@ -628,13 +628,8 @@ def clipped(obj, frame_shape):
|
||||
|
||||
|
||||
def restart_frigate():
|
||||
proc = psutil.Process(1)
|
||||
# if this is running via s6, sigterm pid 1
|
||||
if proc.name() == "s6-svscan":
|
||||
proc.terminate()
|
||||
# otherwise, just try and exit frigate
|
||||
else:
|
||||
os.kill(os.getpid(), signal.SIGTERM)
|
||||
# S6 overlay is configured to exit once the Frigate process exits
|
||||
os.kill(os.getpid(), signal.SIGTERM)
|
||||
|
||||
|
||||
class EventsPerSecond:
|
||||
|
@ -78,7 +78,7 @@ export default function AppBar() {
|
||||
{showDialogWait ? (
|
||||
<Prompt
|
||||
title="Restart in progress"
|
||||
text="Please wait a few seconds for the restart to complete before reloading the page."
|
||||
text="This can take up to one minute, please wait before reloading the page."
|
||||
/>
|
||||
) : null}
|
||||
</Fragment>
|
||||
|
Loading…
Reference in New Issue
Block a user