From 89236a8ad93bbfa39b935afc8eabdaab5a1e2474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Fri, 25 Nov 2016 00:10:15 +0100 Subject: [PATCH] Deb: skip invoke-rc.d mysql stop if no mysql process is running at all Quite often in upgrades on systemd systems dpkg emitted an error like: Failed to stop mysql.service: Unit mysql.service not loaded. invoke-rc.d: initscript mysql, action "stop" failed. invoke-rc.d returned 5 There is a MySQL server running, but we failed in our attempts to stop it. Stop it yourself and try again! dpkg: error processing archive /var/cache/apt/archives/mariadb-server-10.2 This is because the mariadb/mysql.service file is not loaded during the upgrade/unpack stage of dpkg in certain situations. With this simple check we can easily skip the shutdown step when it is really not needed, which is for sure the case if no mysqld process at all is running on the entire system. --- debian/mariadb-server-10.2.preinst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/debian/mariadb-server-10.2.preinst b/debian/mariadb-server-10.2.preinst index 9804b1ccd6e53..9c37cba7a9c0f 100644 --- a/debian/mariadb-server-10.2.preinst +++ b/debian/mariadb-server-10.2.preinst @@ -23,6 +23,10 @@ mysql_upgradedir=/var/lib/mysql-upgrade stop_server() { if [ ! -x /etc/init.d/mysql ]; then return; fi + # Return immediately if there are no mysql processes running + # as there is no point in trying to shutdown in that case. + if ! pgrep mysqld > /dev/null; then return; fi + set +e if [ -x /usr/sbin/invoke-rc.d ]; then cmd="invoke-rc.d mysql stop"