From a4052a9fe5c5630abe234cc6156cff31acdd2e03 Mon Sep 17 00:00:00 2001 From: ElMoribond Date: Mon, 21 Jun 2021 17:00:50 +0200 Subject: [PATCH] Add ability to restart --- frigate/mqtt.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frigate/mqtt.py b/frigate/mqtt.py index bc10e95c8..dddbf4767 100644 --- a/frigate/mqtt.py +++ b/frigate/mqtt.py @@ -13,6 +13,7 @@ from ws4py.server.wsgiutils import WebSocketWSGIApplication from ws4py.websocket import WebSocket from frigate.config import FrigateConfig +from frigate.util import restart_frigate logger = logging.getLogger(__name__) @@ -88,6 +89,14 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics): state_topic = f"{message.topic[:-4]}/state" client.publish(state_topic, payload, retain=True) + def on_restart_command(client, userdata, message): + payload = message.payload.decode() + if payload == "container": + logger.warning(f"Restart container received via mqtt") + restart_frigate() + else: + logger.warning(f"Received unsupported value at {message.topic}: {payload}") + def on_connect(client, userdata, flags, rc): threading.current_thread().name = "mqtt" if rc != 0: @@ -125,6 +134,10 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics): f"{mqtt_config.topic_prefix}/{name}/detect/set", on_detect_command ) + client.message_callback_add( + f"{mqtt_config.topic_prefix}/restart", on_restart_command + ) + if not mqtt_config.tls_ca_certs is None: if ( not mqtt_config.tls_client_cert is None