fix: remove aggressive OBS kill behaviour
Checks for existing OBS process, and tries to connect to that
This commit is contained in:
@@ -33,11 +33,7 @@ def shutdown(signum, frame):
|
|||||||
signal.signal(signal.SIGINT, shutdown)
|
signal.signal(signal.SIGINT, shutdown)
|
||||||
signal.signal(signal.SIGTERM, shutdown)
|
signal.signal(signal.SIGTERM, shutdown)
|
||||||
|
|
||||||
def open_obs():
|
def clean_obs_sentinel_files():
|
||||||
kill_command = subprocess.run(['pkill', 'obs'])
|
|
||||||
if kill_command.returncode not in [0, 1]:
|
|
||||||
raise SystemError("Could not kill existing OBS instance")
|
|
||||||
|
|
||||||
if os.path.exists(SENTINEL_FILE):
|
if os.path.exists(SENTINEL_FILE):
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(SENTINEL_FILE)
|
shutil.rmtree(SENTINEL_FILE)
|
||||||
@@ -45,6 +41,14 @@ def open_obs():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Could not delete OBS .sentinel directory: {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
|
# 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)
|
||||||
|
|
||||||
@@ -104,7 +108,13 @@ class Handler(FileSystemEventHandler):
|
|||||||
logger.info(f"Added new 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():
|
||||||
|
logger.info("OBS is already running")
|
||||||
|
else:
|
||||||
|
logger.info("OBS is not running, starting it now")
|
||||||
|
clean_obs_sentinel_files()
|
||||||
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"])
|
||||||
|
|
||||||
|
|||||||
@@ -104,4 +104,4 @@ def cleanup_state(max_age_seconds: float) -> None:
|
|||||||
|
|
||||||
def create_state_file_if_needed() -> None:
|
def create_state_file_if_needed() -> None:
|
||||||
if not get_state_file_path().exists():
|
if not get_state_file_path().exists():
|
||||||
write_state(EMPTY_STATE)
|
write_state(EMPTY_STATE.copy())
|
||||||
|
|||||||
Reference in New Issue
Block a user