From c58addff2658ce269bb29d5bd7ca22e1c8ebceb0 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sat, 21 Feb 2026 21:14:20 +0000 Subject: [PATCH] fix: remove aggressive OBS kill behaviour Checks for existing OBS process, and tries to connect to that --- rewind/daemon.py | 22 ++++++++++++++++------ rewind/state.py | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/rewind/daemon.py b/rewind/daemon.py index 223213d..68cb9ba 100755 --- a/rewind/daemon.py +++ b/rewind/daemon.py @@ -33,11 +33,7 @@ def shutdown(signum, frame): signal.signal(signal.SIGINT, shutdown) signal.signal(signal.SIGTERM, shutdown) -def open_obs(): - kill_command = subprocess.run(['pkill', 'obs']) - if kill_command.returncode not in [0, 1]: - raise SystemError("Could not kill existing OBS instance") - +def clean_obs_sentinel_files(): if os.path.exists(SENTINEL_FILE): try: shutil.rmtree(SENTINEL_FILE) @@ -45,6 +41,14 @@ def open_obs(): except Exception as e: logger.error(f"Could not delete OBS .sentinel directory: {e}") +def is_obs_running(): + result = subprocess.run( + ["pgrep", "-x", "obs"], + stdout=subprocess.PIPE + ) + return result.returncode == 0 + +def open_obs(): # Using and not checking OBS since it needs to be non-blocking subprocess.Popen(["obs", "--minimize-to-tray"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) @@ -104,7 +108,13 @@ class Handler(FileSystemEventHandler): logger.info(f"Added new file to state: {event.src_path}") def main() -> None: - open_obs() + if is_obs_running(): + logger.info("OBS is already running") + else: + logger.info("OBS is not running, starting it now") + clean_obs_sentinel_files() + open_obs() + config = load_config() con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"]) diff --git a/rewind/state.py b/rewind/state.py index da4052d..52fd92b 100644 --- a/rewind/state.py +++ b/rewind/state.py @@ -104,4 +104,4 @@ def cleanup_state(max_age_seconds: float) -> None: def create_state_file_if_needed() -> None: if not get_state_file_path().exists(): - write_state(EMPTY_STATE) + write_state(EMPTY_STATE.copy())