fix(linux): report a Service state restore failure after reinstall

Refs #8515

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Tunglies
2026-11-09 20:28:37 +08:00
co-authored by Copilot
parent f8a0d50a76
commit a635573664
2 changed files with 20 additions and 12 deletions
+10 -6
View File
@@ -45,21 +45,25 @@ reinstall_existing_service() {
if systemctl is-active --quiet "$SERVICE_UNIT"; then
active=yes
fi
local status=0 restored=yes
if [ "$enabled" = "masked-runtime" ]; then
systemctl unmask --runtime --quiet "$SERVICE_UNIT"
systemctl unmask --runtime --quiet "$SERVICE_UNIT" || restored=no
fi
local status=0
if ! CLASH_VERGE_SERVICE_GID="$gid" /usr/bin/clash-verge-service-install --install-service; then
echo "Warning: reinstalling Clash Verge Service failed; Clash Verge will offer to reinstall it." >&2
status=1
fi
case "$enabled" in
disabled) systemctl disable --quiet "$SERVICE_UNIT" ;;
enabled-runtime) systemctl disable --quiet "$SERVICE_UNIT" && systemctl enable --runtime --quiet "$SERVICE_UNIT" ;;
masked-runtime) systemctl mask --runtime --quiet "$SERVICE_UNIT" ;;
disabled) systemctl disable --quiet "$SERVICE_UNIT" || restored=no ;;
enabled-runtime) { systemctl disable --quiet "$SERVICE_UNIT" && systemctl enable --runtime --quiet "$SERVICE_UNIT"; } || restored=no ;;
masked-runtime) systemctl mask --runtime --quiet "$SERVICE_UNIT" || restored=no ;;
esac
if [ "$active" = "no" ]; then
systemctl stop "$SERVICE_UNIT"
systemctl stop "$SERVICE_UNIT" || restored=no
fi
if [ "$restored" = "no" ]; then
echo "Warning: restoring the previous Clash Verge Service state (${enabled:-unknown}, active=$active) failed; check it with systemctl." >&2
status=1
fi
return "$status"
}
+10 -6
View File
@@ -32,21 +32,25 @@ reinstall_existing_service() {
if systemctl is-active --quiet "$SERVICE_UNIT"; then
active=yes
fi
local status=0 restored=yes
if [ "$enabled" = "masked-runtime" ]; then
systemctl unmask --runtime --quiet "$SERVICE_UNIT"
systemctl unmask --runtime --quiet "$SERVICE_UNIT" || restored=no
fi
local status=0
if ! CLASH_VERGE_SERVICE_GID="$gid" /usr/bin/clash-verge-service-install --install-service; then
echo "Warning: reinstalling Clash Verge Service failed; Clash Verge will offer to reinstall it." >&2
status=1
fi
case "$enabled" in
disabled) systemctl disable --quiet "$SERVICE_UNIT" ;;
enabled-runtime) systemctl disable --quiet "$SERVICE_UNIT" && systemctl enable --runtime --quiet "$SERVICE_UNIT" ;;
masked-runtime) systemctl mask --runtime --quiet "$SERVICE_UNIT" ;;
disabled) systemctl disable --quiet "$SERVICE_UNIT" || restored=no ;;
enabled-runtime) { systemctl disable --quiet "$SERVICE_UNIT" && systemctl enable --runtime --quiet "$SERVICE_UNIT"; } || restored=no ;;
masked-runtime) systemctl mask --runtime --quiet "$SERVICE_UNIT" || restored=no ;;
esac
if [ "$active" = "no" ]; then
systemctl stop "$SERVICE_UNIT"
systemctl stop "$SERVICE_UNIT" || restored=no
fi
if [ "$restored" = "no" ]; then
echo "Warning: restoring the previous Clash Verge Service state (${enabled:-unknown}, active=$active) failed; check it with systemctl." >&2
status=1
fi
return "$status"
}