diff options
Diffstat (limited to 'debian/mariadb-server-10.8.postrm')
-rw-r--r-- | debian/mariadb-server-10.8.postrm | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/debian/mariadb-server-10.8.postrm b/debian/mariadb-server-10.8.postrm index 94ce91db31d..41ed3ffe979 100644 --- a/debian/mariadb-server-10.8.postrm +++ b/debian/mariadb-server-10.8.postrm @@ -1,12 +1,18 @@ #!/bin/bash set -e +# shellcheck source=/dev/null . /usr/share/debconf/confmodule # Automatically set version to ease maintenance of this file MAJOR_VER="${DPKG_MAINTSCRIPT_PACKAGE#mariadb-server-}" -if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi +if [ -n "$DEBIAN_SCRIPT_DEBUG" ] +then + set -v -x + DEBIAN_SCRIPT_TRACE=1 +fi + ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" @@ -15,38 +21,43 @@ MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" # do it himself. No database directories should be removed while the server # is running! Another mariadbd in e.g. a different chroot is fine for us. stop_server() { - # Return immediately if there are no mysqld processes running - # as there is no point in trying to shutdown in that case. - if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi - - set +e - invoke-rc.d mariadb stop - invoke-rc.d mysql stop # Backwards compatibility - errno=$? - set -e - - # systemctl could emit exit code 100=no init script (fresh install) - if [ "$errno" != 0 -a "$errno" != 100 ]; then - echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2 - echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2 - echo "Stop it yourself and try again!" 1>&2 - db_stop - exit 1 - fi + # Return immediately if there are no mysqld processes running + # as there is no point in trying to shutdown in that case. + if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null + then + return + fi + + set +e + invoke-rc.d mariadb stop + invoke-rc.d mysql stop # Backwards compatibility + errno=$? + set -e + + # systemctl could emit exit code 100=no init script (fresh install) + if [ "$errno" != 0 ] && [ "$errno" != 100 ] + then + echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2 + echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2 + echo "Stop it yourself and try again!" 1>&2 + db_stop + exit 1 + fi } case "$1" in purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) - if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then + if [ -n "$($MYADMIN ping 2>/dev/null)" ] + then stop_server sleep 2 fi - ;; + ;; *) echo "postrm called with unknown argument '$1'" 1>&2 exit 1 - ;; + ;; esac # @@ -54,7 +65,8 @@ esac # - Remove the mysql user only after all his owned files are purged. # - Cleanup the initscripts only if this was the last provider of them # -if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ]; then +if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ] +then # we remove the mysql user only after all his owned files are purged rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz} rm -rf /var/log/mysql @@ -62,7 +74,8 @@ if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ]; then db_input high "mariadb-server-$MAJOR_VER/postrm_remove_databases" || true db_go || true db_get "mariadb-server-$MAJOR_VER/postrm_remove_databases" || true - if [ "$RET" = "true" ]; then + if [ "$RET" = "true" ] + then # never remove the debian.cnf when the databases are still existing # else we ran into big trouble on the next install! rm -f /etc/mysql/debian.cnf @@ -75,9 +88,9 @@ if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ]; then if [ -d /var/lib/mysql ] then find /var/lib/mysql -mindepth 1 \ - -not -path '*/lost+found/*' -not -name 'lost+found' \ - -not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \ - -delete + -not -path '*/lost+found/*' -not -name 'lost+found' \ + -not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \ + -delete # "|| true" still needed as rmdir still exits with non-zero if # /var/lib/mysql is a mount point @@ -92,6 +105,7 @@ fi #DEBHELPER# # Modified dh_systemd_start snippet that's not added automatically -if [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true +if [ -d /run/systemd/system ] +then + systemctl --system daemon-reload >/dev/null || true fi |