fix: unblock add-node API and improve online status detection
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-4
@@ -97,7 +97,7 @@ def login_required(view):
|
||||
return wrapped
|
||||
|
||||
|
||||
def apply_singbox() -> tuple[bool, str]:
|
||||
def render_singbox_config() -> tuple[bool, str]:
|
||||
env = os.environ.copy()
|
||||
env["JIEDIAN_ROOT"] = str(ROOT)
|
||||
proc = subprocess.run(
|
||||
@@ -108,9 +108,23 @@ def apply_singbox() -> tuple[bool, str]:
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
return False, proc.stderr or proc.stdout or "配置生成失败"
|
||||
restart = subprocess.run(["systemctl", "restart", "sing-box"], capture_output=True, text=True)
|
||||
if restart.returncode != 0:
|
||||
return False, restart.stderr or restart.stdout or "sing-box 重启失败"
|
||||
return True, "ok"
|
||||
|
||||
|
||||
def restart_singbox_async() -> None:
|
||||
"""后台重启 sing-box,避免添加/删除节点 API 长时间阻塞。"""
|
||||
subprocess.Popen(
|
||||
["systemctl", "restart", "sing-box"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
|
||||
def apply_singbox() -> tuple[bool, str]:
|
||||
ok, msg = render_singbox_config()
|
||||
if not ok:
|
||||
return False, msg
|
||||
restart_singbox_async()
|
||||
return True, "ok"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user