Skip to content
Snippets Groups Projects
Commit 6e5ee72d authored by Otto Kekäläinen's avatar Otto Kekäläinen
Browse files

Unify server preinst and postrm server stopping function

We cannot use systemctl directly as it might not be available on all
platforms.
parent c40f91fa
No related branches found
No related tags found
No related merge requests found
......@@ -13,18 +13,25 @@ MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# Try to stop the server in a sane way. If it does not success let the admin
# do it himself. No database directories should be removed while the server
# is running!
# is running! Another mysqld in e.g. a different chroot is fine for us.
stop_server() {
set +e
invoke-rc.d mysql stop
errno=$?
set -e
# Return immediately if there are no mysql processes running
# as there is no point in trying to shutdown in that case.
if ! pgrep -x mysqld > /dev/null; then return; fi
if [ "$?" != 0 ]; then
echo "Trying to stop the MySQL server resulted in exitcode $?." 1>&2
echo "Stop it yourself and try again!" 1>&2
exit 1
fi
set +e
invoke-rc.d mysql stop
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
}
case "$1" in
......
......@@ -33,14 +33,14 @@ stop_server() {
if ! pgrep -x mysqld > /dev/null; then return; fi
set +e
systemctl stop mysql
invoke-rc.d mysql stop
errno=$?
set -e
# 0=ok, 100=no init script (fresh install)
# systemctl could emit exit code 100=no init script (fresh install)
if [ "$errno" != 0 -a "$errno" != 100 ]; then
echo "'systemctl stop mysql' returned $errno" 1>&2
echo "There is a MySQL server running, but we failed in our attempts to stop it." 1>&2
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment