diff --git a/linux-x64/phserver/phserver.sh b/linux-x64/phserver/phserver.sh index e235236..57d242b 100755 --- a/linux-x64/phserver/phserver.sh +++ b/linux-x64/phserver/phserver.sh @@ -14,6 +14,17 @@ fi # Ensure AppImage has execute permission chmod +x "${APPIMAGE}" +# 互斥锁:sunshine 运行期间(含下方 --wait 等待登录)持锁,阻止重复拉起。 +# PH 监控约 15 秒判一次 not running:若本脚本还在 --wait 等登录,PH 会再 Start 一个, +# 双实例竞争端口(47990 bind 冲突退出、存活实例 nvhttp 端口不完整),moonlight 无法发现。 +# 锁放脚本同目录(部署目录):unit 的 ProtectSystem=strict 已放行其读写, +# 且不受 PrivateTmp 影响(服务与手动执行共享同一把锁)。 +exec 9>"${SCRIPT_DIR}/phserver.lock" +if ! flock -n 9; then + echo "phserver.sh already running (lock held), exit" + exit 0 +fi + # 每次拉起 sunshine 前刷新 /root/.Xauthority(最多等 45 秒登录就绪): # 自愈开机竞态——服务 ExecStartPre 时机可能早于用户登录,cookie 是上次会话的, # 会导致 sunshine capture 初始化失败、串流不可用。脚本不存在/失败不阻断启动。