From 470c775d7aada0626b53fa355b8cac62353e602a Mon Sep 17 00:00:00 2001 From: Shane Date: Thu, 15 May 2025 19:24:17 +1000 Subject: [PATCH] try --- foodie_utils.py | 5 +++-- manage_scripts.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/foodie_utils.py b/foodie_utils.py index 822477e..c74c235 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -1684,15 +1684,16 @@ def prune_system_activity(tweet_reset_time): def is_any_script_running(): """ Check if any script is running by inspecting system_activity.json and verifying PIDs. - Returns True if at least one script is running, False otherwise. + Returns True if at least one script (other than the current process) is running, False otherwise. """ activity_file = "/home/shane/foodie_automator/system_activity.json" + current_pid = os.getpid() try: activities = load_json_file(activity_file, default=[]) logging.debug(f"[DEBUG] system_activity.json contents: {activities}") for entry in activities: logging.debug(f"[DEBUG] Checking entry: {entry}") - if entry.get("status") == "running" and entry.get("pid"): + if entry.get("status") == "running" and entry.get("pid") and entry.get("pid") != current_pid: try: import psutil process = psutil.Process(entry["pid"]) diff --git a/manage_scripts.sh b/manage_scripts.sh index 9d10222..2ab6441 100755 --- a/manage_scripts.sh +++ b/manage_scripts.sh @@ -88,6 +88,25 @@ stop_scripts() { log "Removed lock file for $script_name" fi done + # Mark all running scripts as stopped in system_activity.json + "$VENV_PYTHON" -c " +import json, os +f = '/home/shane/foodie_automator/system_activity.json' +if os.path.exists(f): + with open(f) as fh: + data = json.load(f) + changed = False + for entry in data: + if entry.get('status') == 'running': + entry['status'] = 'stopped' + entry['stop_time'] = __import__('datetime').datetime.now(__import__('datetime').timezone.utc).isoformat() + entry['pid'] = None + changed = True + if changed: + with open(f, 'w') as fh: + json.dump(data, fh, indent=2) ++" + log "Marked all running scripts as stopped in system_activity.json" log "Scripts stopped." }