Shane 7 months ago
parent a193dbacd7
commit 470c775d7a
  1. 5
      foodie_utils.py
  2. 19
      manage_scripts.sh

@ -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"])

@ -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."
}

Loading…
Cancel
Save