开机场景:phserver.sh 在 refresh-xauth --wait 45 等待登录期间,PH 监控 (15 秒周期)判 sunshine 不在再次 Start 本脚本 → 双 sunshine 实例竞争端口 (后起者 47990 bind 冲突退出,存活实例 nvhttp 47984/47989 端口不完整), moonlight 无法发现主机(145 重启后实测)。锁在脚本同目录,sunshine 存活 期间(含等待)持有,重复调用 10ms 内静默退出。 Co-Authored-By: Claude <noreply@anthropic.com>
70 lines
2.5 KiB
Bash
Executable File
70 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Get the absolute path of the script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
APPIMAGE="${SCRIPT_DIR}/sunshine.AppImage"
|
|
|
|
# Check if AppImage file exists
|
|
if [ ! -f "${APPIMAGE}" ]; then
|
|
echo "Error: sunshine.AppImage not found"
|
|
echo "Path: ${APPIMAGE}"
|
|
exit 1
|
|
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 初始化失败、串流不可用。脚本不存在/失败不阻断启动。
|
|
REFRESH_XAUTH="${SCRIPT_DIR}/../refresh-xauth.sh"
|
|
if [ -f "${REFRESH_XAUTH}" ]; then
|
|
"${REFRESH_XAUTH}" --wait 45 || true
|
|
fi
|
|
|
|
# Read system information
|
|
if [ -f /etc/os-release ]; then
|
|
source /etc/os-release
|
|
|
|
# Detect if it's UOS V20 or Kylin V10(两者 glibc 偏老,需 ablrun 提供兼容 libc)
|
|
if [[ "${NAME}" == "uos" && "${VERSION_ID}" == "20" ]] || [[ "${NAME}" == "Kylin" && "${VERSION_ID}" == "v10" ]]; then
|
|
echo "Detected ${NAME} ${VERSION_ID}, running with ablrun..."
|
|
|
|
# 定义 ablrun 的完整路径
|
|
ABLRUN="$(dirname "${BASH_SOURCE[0]}")/abl_portable/usr/bin/ablrun"
|
|
# 检查 ablrun 是否可用
|
|
if [[ -x "${ABLRUN}" ]]; then
|
|
"${ABLRUN}" "${APPIMAGE}" "$@"
|
|
else
|
|
echo "Warning: ablrun not found at ${ABLRUN}, trying direct execution..."
|
|
"${APPIMAGE}" "$@"
|
|
fi
|
|
else
|
|
echo "Detected system: ${NAME} ${VERSION_ID}"
|
|
echo "Running sunshine.AppImage directly..."
|
|
"${APPIMAGE}" "$@"
|
|
fi
|
|
else
|
|
echo "Warning: Cannot read /etc/os-release, running AppImage directly..."
|
|
"${APPIMAGE}" "$@"
|
|
fi
|
|
|
|
# Capture exit status
|
|
EXIT_CODE=$?
|
|
if [ ${EXIT_CODE} -ne 0 ]; then
|
|
echo "Program exited abnormally, exit code: ${EXIT_CODE}"
|
|
fi
|
|
|
|
exit ${EXIT_CODE}
|