Spaces:
Sleeping
Sleeping
Update vps_monitor.py
Browse files- vps_monitor.py +11 -10
vps_monitor.py
CHANGED
@@ -79,21 +79,22 @@ def check_and_run_script(config):
|
|
79 |
|
80 |
# 检查进程是否在运行
|
81 |
if last_pid:
|
82 |
-
check_command = f"ps -p {last_pid} -o pid
|
83 |
else:
|
84 |
-
check_command = f"
|
85 |
|
86 |
stdin, stdout, stderr = client.exec_command(check_command)
|
87 |
-
|
88 |
|
89 |
-
if
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
status = "Running"
|
92 |
-
|
93 |
-
# 获取运行时间
|
94 |
-
stdin, stdout, stderr = client.exec_command(f"ps -p {pid} -o etime=")
|
95 |
-
runtime = stdout.read().decode('utf-8').strip()
|
96 |
-
|
97 |
logger.info(f"Script {script_name} is running. PID: {pid}, Runtime: {runtime}")
|
98 |
else:
|
99 |
logger.info(f"Script {script_name} not running. Attempting to restart.")
|
|
|
79 |
|
80 |
# 检查进程是否在运行
|
81 |
if last_pid:
|
82 |
+
check_command = f"ps -p {last_pid} -o pid,etime,args"
|
83 |
else:
|
84 |
+
check_command = f"ps aux | grep '{script_path}' | grep -v grep"
|
85 |
|
86 |
stdin, stdout, stderr = client.exec_command(check_command)
|
87 |
+
output = stdout.read().decode('utf-8').strip()
|
88 |
|
89 |
+
if output and (last_pid or script_path in output):
|
90 |
+
parts = output.split()
|
91 |
+
if last_pid:
|
92 |
+
pid = last_pid
|
93 |
+
runtime = parts[1] if len(parts) > 1 else "Unknown"
|
94 |
+
else:
|
95 |
+
pid = parts[1] if len(parts) > 1 else "Unknown"
|
96 |
+
runtime = parts[9] if len(parts) > 9 else "Unknown"
|
97 |
status = "Running"
|
|
|
|
|
|
|
|
|
|
|
98 |
logger.info(f"Script {script_name} is running. PID: {pid}, Runtime: {runtime}")
|
99 |
else:
|
100 |
logger.info(f"Script {script_name} not running. Attempting to restart.")
|