2022-12-07 10:47:40 -03:00
|
|
|
#!/command/with-contenv bash
|
|
|
|
|
# shellcheck shell=bash
|
|
|
|
|
# Start the Frigate service
|
|
|
|
|
|
|
|
|
|
set -o errexit -o nounset -o pipefail
|
|
|
|
|
|
2026-08-30 09:14:43 -05:00
|
|
|
runs_as_root=0
|
|
|
|
|
if [[ "$(id -u)" -eq 0 ]]; then
|
|
|
|
|
if [[ "${FRIGATE_RUN_AS_ROOT:-false}" == "true" ]] || /usr/local/bin/service-runs-as-root frigate; then
|
|
|
|
|
runs_as_root=1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# /root survives s6-setuidgid and breaks cache writes after the drop; set
|
|
|
|
|
# before opt_in_out so the opt-out marker lands where the service will look
|
|
|
|
|
if [[ "$runs_as_root" -eq 0 ]]; then
|
|
|
|
|
export HOME=/config
|
|
|
|
|
fi
|
|
|
|
|
|
2026-09-02 07:49:52 -06:00
|
|
|
# detector runtimes installed at first start (pip install --user) live under
|
|
|
|
|
# $HOME/.local; the dynamic loader only reads LD_LIBRARY_PATH at exec time
|
|
|
|
|
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}${HOME}/.local/lib"
|
|
|
|
|
export PATH="${PATH}:${HOME}/.local/bin"
|
|
|
|
|
|
2025-05-03 07:55:22 -06:00
|
|
|
# opt out of openvino telemetry
|
|
|
|
|
if [ -e /usr/local/bin/opt_in_out ]; then
|
2025-06-13 07:55:08 -06:00
|
|
|
/usr/local/bin/opt_in_out --opt_out > /dev/null 2>&1
|
2025-05-03 07:55:22 -06:00
|
|
|
fi
|
|
|
|
|
|
2023-02-19 16:11:12 -03:00
|
|
|
# Logs should be sent to stdout so that s6 can collect them
|
|
|
|
|
|
2023-01-18 10:53:53 -03:00
|
|
|
# Tell S6-Overlay not to restart this service
|
|
|
|
|
s6-svc -O .
|
|
|
|
|
|
2025-01-18 19:30:35 -07:00
|
|
|
function set_libva_version() {
|
2025-02-20 22:07:41 -03:00
|
|
|
local ffmpeg_path
|
|
|
|
|
ffmpeg_path=$(python3 /usr/local/ffmpeg/get_ffmpeg_path.py)
|
|
|
|
|
LIBAVFORMAT_VERSION_MAJOR=$("$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+")
|
|
|
|
|
export LIBAVFORMAT_VERSION_MAJOR
|
2025-01-18 19:30:35 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-23 13:35:40 -03:00
|
|
|
echo "[INFO] Preparing Frigate..."
|
2025-01-18 19:30:35 -07:00
|
|
|
set_libva_version
|
2025-03-24 11:05:59 -03:00
|
|
|
|
2023-02-19 16:11:12 -03:00
|
|
|
echo "[INFO] Starting Frigate..."
|
2023-01-18 20:23:40 -03:00
|
|
|
|
2023-02-19 16:11:12 -03:00
|
|
|
cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate"
|
2022-12-07 10:47:40 -03:00
|
|
|
|
|
|
|
|
# Replace the bash process with the Frigate process, redirecting stderr to stdout
|
|
|
|
|
exec 2>&1
|
2026-08-30 09:14:43 -05:00
|
|
|
if [[ "$(id -u)" -ne 0 || "$runs_as_root" -eq 1 ]]; then
|
|
|
|
|
exec python3 -u -m frigate
|
|
|
|
|
else
|
|
|
|
|
exec s6-setuidgid frigate python3 -u -m frigate
|
|
|
|
|
fi
|