Update main.py
Browse files4 unmodified lines567891015 unmodified lines262728293031325 unmodified lines3839404142433 unmodified lines474849505152535455565758596061624 unmodified lines# 获取环境变量 UUIDUUID = os.environ.get('KEY')# 生成 sing-box 配置conf = json.dumps({15 unmodified lines],"transport": {"type": "ws","path": "/ws"}}],5 unmodified lines]}, indent=2)# 写入配置文件with open("/etc/sing-box/config.json", "w", encoding="utf-8") as f:f.write(conf)3 unmodified linesprocess = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)# 检查 sing-box 是否启动成功timeout = 10 # 等待 10 秒start_time = time.time()while time.time() - start_time < timeout:if process.poll() is not None: # 进程已退出stdout, stderr = process.communicate()print(f"Error: sing-box failed to start. Stdout: {stdout}, Stderr: {stderr}")exit(1)# 检查日志输出,确认启动line = process.stdout.readline()if "started" in line.lower(): # sing-box 日志包含 "started" 表示启动成功print("hello world")breaktime.sleep(0.1)4 unmodified lines567891011121315 unmodified lines293031323334355 unmodified lines4142434445464748493 unmodified lines535455565758596061626364656667684 unmodified lines# 获取环境变量 UUIDUUID = os.environ.get('KEY')if not UUID:print("Error: KEY environment variable not set")exit(1)# 生成 sing-box 配置conf = json.dumps({15 unmodified lines],"transport": {"type": "ws","path": "/vless-ws" # 更改路径以避免代理冲突}}],5 unmodified lines]}, indent=2)# 调试输出配置print("Generated config:", conf)# 写入配置文件with open("/etc/sing-box/config.json", "w", encoding="utf-8") as f:f.write(conf)3 unmodified linesprocess = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)# 检查 sing-box 是否启动成功timeout = 10start_time = time.time()while time.time() - start_time < timeout:if process.poll() is not None:stdout, stderr = process.communicate()print(f"Error: sing-box failed. Stdout: {stdout}, Stderr: {stderr}")exit(1)line = process.stdout.readline()print("sing-box log:", line.strip()) # 调试日志if "started" in line.lower():print("hello world")breaktime.sleep(0.1)
main.py+12-6