From ac53993f7048c0a76a20cdac630dacd00b064534 Mon Sep 17 00:00:00 2001 From: coperni <5769938+coperni@users.noreply.github.com> Date: Fri, 3 Nov 2023 22:19:29 -0400 Subject: [PATCH] Add endpoint to restart Frigate (#8440) * Add endpoint to restart Frigate The only means of restarting Frigate remotely is to issue a restart topic on the server's websocket. It's convenient to also expose this capability via HTTP endpoint. * Add new section to API docs * Remove extra line --- docs/docs/integrations/api.md | 4 ++++ frigate/http.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/docs/integrations/api.md b/docs/docs/integrations/api.md index 09a7be284..304cec60e 100644 --- a/docs/docs/integrations/api.md +++ b/docs/docs/integrations/api.md @@ -365,3 +365,7 @@ Recording retention config still applies to manual events, if frigate is configu ### `PUT /api/events//end` End a specific manual event without a predetermined length. + +### `POST /api/restart` + +Restarts Frigate process. diff --git a/frigate/http.py b/frigate/http.py index 9566a067c..297b2f2e5 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -2103,3 +2103,30 @@ def logs(service: str): jsonify({"success": False, "message": "Could not find log file"}), 500, ) + + +@bp.route("/restart", methods=["POST"]) +def restart(): + try: + restart_frigate() + except Exception as e: + logging.error(f"Error restarting Frigate: {e}") + return make_response( + jsonify( + { + "success": False, + "message": "Unable to restart Frigate.", + } + ), + 500, + ) + + return make_response( + jsonify( + { + "success": True, + "message": "Restarting (this can take up to one minute)...", + } + ), + 200, + )