From 5acfece5b86409fd6c20cff0ea34d1c5a7397767 Mon Sep 17 00:00:00 2001 From: Zhanghu Date: Fri, 6 Nov 2026 21:46:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20phserver.sh=20=E5=8A=A0=20flock=20?= =?UTF-8?q?=E4=BA=92=E6=96=A5,=E9=98=B2=20PH=20=E7=9B=91=E6=8E=A7=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=8B=89=E8=B5=B7=E5=AF=BC=E8=87=B4=20sunshine=20?= =?UTF-8?q?=E5=8F=8C=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 开机场景:phserver.sh 在 refresh-xauth --wait 45 等待登录期间,PH 监控 (15 秒周期)判 sunshine 不在再次 Start 本脚本 → 双 sunshine 实例竞争端口 (后起者 47990 bind 冲突退出,存活实例 nvhttp 47984/47989 端口不完整), moonlight 无法发现主机(145 重启后实测)。锁在脚本同目录,sunshine 存活 期间(含等待)持有,重复调用 10ms 内静默退出。 Co-Authored-By: Claude --- linux-x64/phserver/phserver.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 初始化失败、串流不可用。脚本不存在/失败不阻断启动。