From f8c572e1122bffc3af93a35d40a0fe7296a628b6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 23 Apr 2026 15:20:34 +0800 Subject: [PATCH] fix: detect stale mariadb service file when server package is missing has_local_mariadb_service() only checked if the systemd unit file existed, but not whether the mariadb-server package was actually installed. When the package was removed but the service file remained, the script would skip server installation and fail on restart. Now verifies the server package is installed via dpkg/rpm in addition to the unit file check. --- install.sh | 18 +++++++++++++++++- x-ui.sh | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 7eb7bba0..08dfcb0b 100644 --- a/install.sh +++ b/install.sh @@ -104,7 +104,23 @@ has_mariadb_cli() { has_local_mariadb_service() { if command -v systemctl >/dev/null 2>&1; then - systemctl list-unit-files 2>/dev/null | grep -qE '^(mariadb|mysql)\.service$' && return 0 + # Also verify the server package is actually installed (not just a stale service file) + if systemctl list-unit-files 2>/dev/null | grep -qE '^(mariadb|mysql)\.service$'; then + case "${release}" in + ubuntu | debian | armbian | linuxmint) + dpkg -s mariadb-server >/dev/null 2>&1 && return 0 + # Package missing but service file exists — stale state + return 1 + ;; + centos | rhel | almalinux | rocky | ol | alinux | amzn | fedora) + rpm -q mariadb-server >/dev/null 2>&1 && return 0 + return 1 + ;; + *) + return 0 + ;; + esac + fi fi [[ -f /etc/init.d/mariadb ]] } diff --git a/x-ui.sh b/x-ui.sh index f5854dd9..7ac63c60 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -2904,7 +2904,23 @@ mariadb_cli_bin() { has_local_mariadb_service() { if command -v systemctl >/dev/null 2>&1; then - systemctl list-unit-files 2>/dev/null | grep -qE '^(mariadb|mysql)\.service$' && return 0 + # Also verify the server package is actually installed (not just a stale service file) + if systemctl list-unit-files 2>/dev/null | grep -qE '^(mariadb|mysql)\.service$'; then + case "${release}" in + ubuntu | debian | armbian | linuxmint) + dpkg -s mariadb-server >/dev/null 2>&1 && return 0 + # Package missing but service file exists — stale state + return 1 + ;; + centos | rhel | almalinux | rocky | ol | alinux | amzn | fedora) + rpm -q mariadb-server >/dev/null 2>&1 && return 0 + return 1 + ;; + *) + return 0 + ;; + esac + fi fi [[ -f /etc/init.d/mariadb ]] }