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.
This commit is contained in:
root 2026-04-23 15:20:34 +08:00
parent 27c2430d4f
commit f8c572e112
2 changed files with 34 additions and 2 deletions

View file

@ -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 ]]
}

18
x-ui.sh
View file

@ -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 ]]
}