From 4baa26b0f4f2a1311f8afe9b1aa6adb1769475b6 Mon Sep 17 00:00:00 2001 From: Russell Troxel Date: Wed, 18 Oct 2023 18:01:52 -0700 Subject: [PATCH] Add docs & test live Signed-off-by: Russell Troxel --- docs/docs/configuration/advanced.md | 31 +++++++++++++++++++++++++++++ frigate/app.py | 12 ++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/docs/configuration/advanced.md b/docs/docs/configuration/advanced.md index d652b3526..ecdd24a1f 100644 --- a/docs/docs/configuration/advanced.md +++ b/docs/docs/configuration/advanced.md @@ -128,3 +128,34 @@ To do this: 2. Rename the build to `go2rtc`. 3. Give `go2rtc` execute permission. 4. Restart Frigate and the custom version will be used, you can verify by checking go2rtc logs. + +## Validating your config.yaml file updates + +When frigate starts up, it checks whether your config file is valid, and if it is not, the process exits. To minimize interruptions when updating your config, you have two options -- you can either leverage the config update API endpoint, or you can validate on the command line using the frigate docker container. + +### Via API + +Frigate can accept a new configuration file as JSON at the `/config/save` endpoint. When updating the config this way, Frigate will validate the config before saving it, and return a `400` if the config is not valid. + +```bash +curl -X POST http://frigate_host:5000/config/save -d @config.json +``` + +if you'd like you can use your yaml config directly by using [`yq`](https://github.com/mikefarah/yq) to convert it to json: + +```bash +yq r -j config.yml | curl -X POST http://frigate_host:5000/config/save -d @- +``` + +### Via Command Line + +You can also validate your config at the command line by using the docker container itself. In CI/CD, you leverage the return code to determine if your config is valid, Frigate will return `1` if the config is invalid, or `0` if it's valid. + +```bash +docker run \ + -v $(pwd)/config.yml:/config/config.yml \ + --entrypoint python3 \ + ghcr.io/blakeblackshear/frigate:stable \ + -u -m frigate \ + --validate_config +``` diff --git a/frigate/app.py b/frigate/app.py index 08a17b38e..c9824bdfd 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -602,6 +602,12 @@ class FrigateApp: print("*************************************************************") self.log_process.terminate() sys.exit(1) + if args.validate_config: + print("*************************************************************") + print("*** Your config file is valid. ***") + print("*************************************************************") + self.log_process.terminate() + sys.exit(0) self.set_environment_vars() self.set_log_levels() self.init_queues() @@ -617,11 +623,7 @@ class FrigateApp: self.log_process.terminate() sys.exit(1) - if args.validate_config: - print("*************************************************************") - print("*** Your config file is valid. ***") - print("*************************************************************") - sys.exit(0) + self.start_detectors() self.start_video_output_processor()