From 22872570806d6ac6ce865ac3ce099cac09dd3235 Mon Sep 17 00:00:00 2001 From: 13315423919 <13315423919@qq.com> Date: Wed, 19 Nov 2025 19:43:00 +0800 Subject: [PATCH] Add File --- main/daemon | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 main/daemon diff --git a/main/daemon b/main/daemon new file mode 100644 index 0000000..de87034 --- /dev/null +++ b/main/daemon @@ -0,0 +1,32 @@ +import subprocess +import os +import sys + +def start_background_process(command,name): + # Start a new process + with open(os.devnull, 'w') as f: + process = subprocess.Popen( + command, + stdout=f, + stderr=subprocess.STDOUT, + preexec_fn=os.setsid # This detaches the process from the terminal + ) + print(f"Started {name} with PID: {process.pid}") + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python3 daemon [args...]") + sys.exit(1) + + if sys.argv[1]=='uvicorn': + full_command = sys.argv[1:] + elif sys.argv[1]=='gunicorn': + full_command = sys.argv[1:] + else: + full_command = ['python3']+sys.argv[1:] + + + start_background_process(full_command,sys.argv[1]) + + +