try
This commit is contained in:
+3
-2
@@ -1684,15 +1684,16 @@ def prune_system_activity(tweet_reset_time):
|
|||||||
def is_any_script_running():
|
def is_any_script_running():
|
||||||
"""
|
"""
|
||||||
Check if any script is running by inspecting system_activity.json and verifying PIDs.
|
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"
|
activity_file = "/home/shane/foodie_automator/system_activity.json"
|
||||||
|
current_pid = os.getpid()
|
||||||
try:
|
try:
|
||||||
activities = load_json_file(activity_file, default=[])
|
activities = load_json_file(activity_file, default=[])
|
||||||
logging.debug(f"[DEBUG] system_activity.json contents: {activities}")
|
logging.debug(f"[DEBUG] system_activity.json contents: {activities}")
|
||||||
for entry in activities:
|
for entry in activities:
|
||||||
logging.debug(f"[DEBUG] Checking entry: {entry}")
|
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:
|
try:
|
||||||
import psutil
|
import psutil
|
||||||
process = psutil.Process(entry["pid"])
|
process = psutil.Process(entry["pid"])
|
||||||
|
|||||||
@@ -88,6 +88,25 @@ stop_scripts() {
|
|||||||
log "Removed lock file for $script_name"
|
log "Removed lock file for $script_name"
|
||||||
fi
|
fi
|
||||||
done
|
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."
|
log "Scripts stopped."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user