Spaces:
Sleeping
Sleeping
Update vps_monitor.py
Browse files- vps_monitor.py +10 -11
vps_monitor.py
CHANGED
@@ -79,22 +79,21 @@ 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 |
-
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.")
|
|
|
79 |
|
80 |
# 检查进程是否在运行
|
81 |
if last_pid:
|
82 |
+
check_command = f"ps -p {last_pid} -o pid="
|
83 |
else:
|
84 |
+
check_command = f"pgrep -f '{script_path}'"
|
85 |
|
86 |
stdin, stdout, stderr = client.exec_command(check_command)
|
87 |
+
pid_output = stdout.read().decode('utf-8').strip()
|
88 |
|
89 |
+
if pid_output:
|
90 |
+
pid = pid_output.split('\n')[0] # 如果有多行,取第一行
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|