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:
@@ -27,15 +27,14 @@ def _install_linux(program_path: str):
|
||||
obs_service = systemd_dir / "obs.service"
|
||||
daemon_service = systemd_dir / "rewind-daemon.service"
|
||||
|
||||
if obs_service.exists():
|
||||
print("obs.service already exists, skipping creation")
|
||||
else:
|
||||
obs_service.write_text("""[Unit]
|
||||
obs_service.write_text("""[Unit]
|
||||
Description=OBS Studio
|
||||
After=graphical-session.target
|
||||
Wants=graphical-session.target
|
||||
|
||||
[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
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
@@ -44,10 +43,7 @@ RestartSec=3
|
||||
WantedBy=default.target
|
||||
""")
|
||||
|
||||
if daemon_service.exists():
|
||||
print("rewind-daemon.service already exists, skipping creation")
|
||||
else:
|
||||
daemon_service.write_text(f"""[Unit]
|
||||
daemon_service.write_text(f"""[Unit]
|
||||
Description=Rewind Daemon
|
||||
After=obs.service
|
||||
Requires=obs.service
|
||||
|
||||
@@ -8,7 +8,6 @@ import logging
|
||||
import shutil
|
||||
import signal
|
||||
|
||||
from pathlib import Path
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
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
|
||||
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
|
||||
init_sleep = 1
|
||||
|
||||
for _ in range(OBS_MAX_RETRIES):
|
||||
for _ in range(obs_max_retries):
|
||||
try:
|
||||
con = obs.ReqClient(host=host, port=port, password=password)
|
||||
except ConnectionRefusedError:
|
||||
@@ -106,7 +105,6 @@ class Handler(FileSystemEventHandler):
|
||||
return
|
||||
|
||||
add_file_to_state(event.src_path)
|
||||
logger.info(f"Added new file to state: {event.src_path}")
|
||||
|
||||
def main() -> None:
|
||||
if is_obs_running():
|
||||
@@ -117,7 +115,7 @@ def main() -> None:
|
||||
open_obs()
|
||||
|
||||
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
|
||||
start_recording(con)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[obs]
|
||||
host = "localhost"
|
||||
port = 4455
|
||||
password = "6BQWrpHLbyJxNLPJ"
|
||||
password = ""
|
||||
|
||||
[record]
|
||||
max_record_time = 28800
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
|
||||
from pathlib import Path
|
||||
from rewind.paths import get_state_dir
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
STATE_NAME = "state.json"
|
||||
EMPTY_STATE = {
|
||||
"files": [],
|
||||
@@ -49,6 +52,8 @@ def add_file_to_state(file_path: str) -> None:
|
||||
state["files"] = files
|
||||
write_state(state)
|
||||
|
||||
logger.info(f"Added new file to state: {file_path}")
|
||||
|
||||
def add_marker_to_state(marker_name: str) -> None:
|
||||
state = load_state()
|
||||
markers = state.get("markers", [])
|
||||
@@ -65,6 +70,8 @@ def add_marker_to_state(marker_name: str) -> None:
|
||||
state["markers"] = markers
|
||||
write_state(state)
|
||||
|
||||
logger.info(f"Added new marker to state: {marker_name}")
|
||||
|
||||
def remove_marker_from_state(marker_name: str) -> None:
|
||||
state = load_state()
|
||||
markers = state.get("markers", [])
|
||||
@@ -73,6 +80,8 @@ def remove_marker_from_state(marker_name: str) -> None:
|
||||
state["markers"] = markers
|
||||
write_state(state)
|
||||
|
||||
logger.info(f"Removed marker from state: {marker_name}")
|
||||
|
||||
def cleanup_state(max_age_seconds: float) -> None:
|
||||
state = load_state()
|
||||
now = datetime.datetime.now().timestamp()
|
||||
|
||||
Reference in New Issue
Block a user