#!/usr/bin/env python # -*- coding: utf-8 -*- import time import subprocess 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 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) if __name__ == "__main__": start_daemon()