Spaces:
Sleeping
Sleeping
Update vps_monitor.py
Browse files- vps_monitor.py +15 -2
vps_monitor.py
CHANGED
@@ -75,9 +75,13 @@ def check_and_run_script(config):
|
|
75 |
script_path = config['script_path']
|
76 |
script_name = os.path.basename(script_path)
|
77 |
|
78 |
-
|
|
|
79 |
stdin, stdout, stderr = client.exec_command(check_command)
|
80 |
-
|
|
|
|
|
|
|
81 |
status = "Running"
|
82 |
logger.info(f"Script {script_name} is running on {config['hostname']}")
|
83 |
else:
|
@@ -91,6 +95,15 @@ def check_and_run_script(config):
|
|
91 |
logger.info(f"Restart script {script_name} executed successfully on {config['hostname']}")
|
92 |
output = stdout.read().decode('utf-8')
|
93 |
logger.info(f"Restart output: {output}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
else:
|
95 |
error_output = stderr.read().decode('utf-8')
|
96 |
status = "Error"
|
|
|
75 |
script_path = config['script_path']
|
76 |
script_name = os.path.basename(script_path)
|
77 |
|
78 |
+
# 使用更精确的检测命令
|
79 |
+
check_command = f"ps aux | grep -v grep | grep -E '{script_path}|{script_name}'"
|
80 |
stdin, stdout, stderr = client.exec_command(check_command)
|
81 |
+
output = stdout.read().decode('utf-8')
|
82 |
+
logger.info(f"Process check output: {output}")
|
83 |
+
|
84 |
+
if output.strip():
|
85 |
status = "Running"
|
86 |
logger.info(f"Script {script_name} is running on {config['hostname']}")
|
87 |
else:
|
|
|
95 |
logger.info(f"Restart script {script_name} executed successfully on {config['hostname']}")
|
96 |
output = stdout.read().decode('utf-8')
|
97 |
logger.info(f"Restart output: {output}")
|
98 |
+
|
99 |
+
# 再次检查进程是否在运行
|
100 |
+
stdin, stdout, stderr = client.exec_command(check_command)
|
101 |
+
output = stdout.read().decode('utf-8')
|
102 |
+
logger.info(f"Process check after restart: {output}")
|
103 |
+
if output.strip():
|
104 |
+
status = "Running (after restart)"
|
105 |
+
else:
|
106 |
+
status = "Restarted (but not running)"
|
107 |
else:
|
108 |
error_output = stderr.read().decode('utf-8')
|
109 |
status = "Error"
|