chore: improve logging and remove service existence check

If the service text needs to be updated, the additional check would not update the service.
This commit is contained in:
2026-04-27 22:06:52 +01:00
parent 974251d1db
commit ef83b7a181
4 changed files with 17 additions and 14 deletions

View File

@@ -27,15 +27,14 @@ def _install_linux(program_path: str):
obs_service = systemd_dir / "obs.service" obs_service = systemd_dir / "obs.service"
daemon_service = systemd_dir / "rewind-daemon.service" daemon_service = systemd_dir / "rewind-daemon.service"
if obs_service.exists(): obs_service.write_text("""[Unit]
print("obs.service already exists, skipping creation")
else:
obs_service.write_text("""[Unit]
Description=OBS Studio Description=OBS Studio
After=graphical-session.target After=graphical-session.target
Wants=graphical-session.target Wants=graphical-session.target
[Service] [Service]
# Ensure OBS sentinel files are cleaned up before starting the daemon
ExecStartPre=-/usr/bin/rm -rf %h/.config/obs-studio/.sentinel
ExecStart=obs --minimize-to-tray ExecStart=obs --minimize-to-tray
Restart=on-failure Restart=on-failure
RestartSec=3 RestartSec=3
@@ -44,10 +43,7 @@ RestartSec=3
WantedBy=default.target WantedBy=default.target
""") """)
if daemon_service.exists(): daemon_service.write_text(f"""[Unit]
print("rewind-daemon.service already exists, skipping creation")
else:
daemon_service.write_text(f"""[Unit]
Description=Rewind Daemon Description=Rewind Daemon
After=obs.service After=obs.service
Requires=obs.service Requires=obs.service

View File

@@ -8,7 +8,6 @@ import logging
import shutil import shutil
import signal import signal
from pathlib import Path
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
from rewind.paths import load_config, get_state_dir from rewind.paths import load_config, get_state_dir
@@ -53,11 +52,11 @@ def open_obs():
# Using and not checking OBS since it needs to be non-blocking # Using and not checking OBS since it needs to be non-blocking
subprocess.Popen(["obs", "--minimize-to-tray"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.Popen(["obs", "--minimize-to-tray"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def open_obs_connection(host: str, port: int, password: str) -> obs.ReqClient: def open_obs_connection(host: str, port: int, password: str, obs_max_retries: int) -> obs.ReqClient:
con = None con = None
init_sleep = 1 init_sleep = 1
for _ in range(OBS_MAX_RETRIES): for _ in range(obs_max_retries):
try: try:
con = obs.ReqClient(host=host, port=port, password=password) con = obs.ReqClient(host=host, port=port, password=password)
except ConnectionRefusedError: except ConnectionRefusedError:
@@ -106,7 +105,6 @@ class Handler(FileSystemEventHandler):
return return
add_file_to_state(event.src_path) add_file_to_state(event.src_path)
logger.info(f"Added new file to state: {event.src_path}")
def main() -> None: def main() -> None:
if is_obs_running(): if is_obs_running():
@@ -117,7 +115,7 @@ def main() -> None:
open_obs() open_obs()
config = load_config() config = load_config()
con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"]) con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"], OBS_MAX_RETRIES)
recording_dir = con.get_record_directory().record_directory recording_dir = con.get_record_directory().record_directory
start_recording(con) start_recording(con)

View File

@@ -1,7 +1,7 @@
[obs] [obs]
host = "localhost" host = "localhost"
port = 4455 port = 4455
password = "6BQWrpHLbyJxNLPJ" password = ""
[record] [record]
max_record_time = 28800 max_record_time = 28800

View File

@@ -2,10 +2,13 @@
import datetime import datetime
import json import json
import os import os
import logging
from pathlib import Path from pathlib import Path
from rewind.paths import get_state_dir from rewind.paths import get_state_dir
logger = logging.getLogger(__name__)
STATE_NAME = "state.json" STATE_NAME = "state.json"
EMPTY_STATE = { EMPTY_STATE = {
"files": [], "files": [],
@@ -49,6 +52,8 @@ def add_file_to_state(file_path: str) -> None:
state["files"] = files state["files"] = files
write_state(state) write_state(state)
logger.info(f"Added new file to state: {file_path}")
def add_marker_to_state(marker_name: str) -> None: def add_marker_to_state(marker_name: str) -> None:
state = load_state() state = load_state()
markers = state.get("markers", []) markers = state.get("markers", [])
@@ -65,6 +70,8 @@ def add_marker_to_state(marker_name: str) -> None:
state["markers"] = markers state["markers"] = markers
write_state(state) write_state(state)
logger.info(f"Added new marker to state: {marker_name}")
def remove_marker_from_state(marker_name: str) -> None: def remove_marker_from_state(marker_name: str) -> None:
state = load_state() state = load_state()
markers = state.get("markers", []) markers = state.get("markers", [])
@@ -73,6 +80,8 @@ def remove_marker_from_state(marker_name: str) -> None:
state["markers"] = markers state["markers"] = markers
write_state(state) write_state(state)
logger.info(f"Removed marker from state: {marker_name}")
def cleanup_state(max_age_seconds: float) -> None: def cleanup_state(max_age_seconds: float) -> None:
state = load_state() state = load_state()
now = datetime.datetime.now().timestamp() now = datetime.datetime.now().timestamp()