fix: handle clean shutdown upon SIGTERM
This commit is contained in:
@@ -7,6 +7,7 @@ import subprocess
|
|||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
import signal
|
||||||
|
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
@@ -29,6 +30,14 @@ OBS_MAX_RETRIES = 10
|
|||||||
seen_files = set()
|
seen_files = set()
|
||||||
seen_lock = Lock()
|
seen_lock = Lock()
|
||||||
|
|
||||||
|
def shutdown(signum, frame):
|
||||||
|
global running
|
||||||
|
logger.info(f"Received signal {signum}, shutting down cleanly")
|
||||||
|
running = False
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, shutdown)
|
||||||
|
signal.signal(signal.SIGTERM, shutdown)
|
||||||
|
|
||||||
def open_obs():
|
def open_obs():
|
||||||
kill_command = subprocess.run(['pkill', 'obs'])
|
kill_command = subprocess.run(['pkill', 'obs'])
|
||||||
if kill_command.returncode not in [0, 1]:
|
if kill_command.returncode not in [0, 1]:
|
||||||
@@ -142,6 +151,10 @@ def main() -> None:
|
|||||||
cleanup_markers(config["record"]["max_record_time"])
|
cleanup_markers(config["record"]["max_record_time"])
|
||||||
time.sleep(INTERVAL)
|
time.sleep(INTERVAL)
|
||||||
finally:
|
finally:
|
||||||
|
if observer:
|
||||||
|
observer.stop()
|
||||||
|
observer.join()
|
||||||
|
|
||||||
stop_recording(con)
|
stop_recording(con)
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
logger.info("Daemon stopped")
|
logger.info("Daemon stopped")
|
||||||
|
|||||||
Reference in New Issue
Block a user