File size: 864 Bytes
00b0e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import subprocess
import time

RESTART_DELAY = 5  # seconds

# Define the commands for both entrypoints
commands = [
    ["python", "-m", "DragMusic"],
    ["python", "server.py"]
]

processes = [None, None]

while True:
    # Start any process that isn't running
    for i, cmd in enumerate(commands):
        if processes[i] is None or processes[i].poll() is not None:
            print(f"[Watchdog] Starting: {' '.join(cmd)}")
            processes[i] = subprocess.Popen(cmd)
            time.sleep(1)  # Stagger startups slightly
    # Check every second if any process has exited
    time.sleep(1)
    for i, proc in enumerate(processes):
        if proc.poll() is not None:
            print(f"[Watchdog] Process {' '.join(commands[i])} exited. Restarting in {RESTART_DELAY} seconds...")
            time.sleep(RESTART_DELAY)
            processes[i] = None