REAPI/daemon.py

26 lines
720 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 += ' &'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
return output.decode(), error.decode()
2024-09-29 15:43:18 +08:00
# 定时执行进程
def process():
command = 'php /www/wwwroot/reapi/public/index.php gateway/api.task/cron 1>/dev/null 2>&1 &'
check = 'ps -ef | grep gateway/api.task/cron | grep -v grep | wc -l'
while True:
value = int(run_command(check)[0].strip())
if value == 0:
run_command(command)
time.sleep(timeSleep)
2024-09-29 15:43:18 +08:00
process()