REAPI/check.py

28 lines
756 B
Python
Raw Normal View History

2024-09-29 15:43:18 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import subprocess
2024-09-29 15:43:18 +08:00
timeSleep = 15
def run_command(command, bg=False):
if bg:
command += ' &'
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout.strip()
def is_process_running(process_name):
try:
output = subprocess.run(['pgrep', '-f', process_name], stdout=subprocess.PIPE, text=True)
return len(output.stdout.strip()) > 0
except Exception:
return False
2024-09-29 15:43:18 +08:00
def start_daemon():
command = 'python /www/sites/reapi/index/daemon.py 1>/dev/null 2>&1 &'
if not is_process_running('daemon.py'):
run_command(command)
2024-09-29 15:43:18 +08:00
if __name__ == "__main__":
start_daemon()