Skip to content

Commit

Permalink
Deb: skip invoke-rc.d mysql stop if no mysql process is running at all
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ottok committed Nov 25, 2016
1 parent e726ae6 commit 89236a8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions debian/mariadb-server-10.2.preinst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 89236a8

Please sign in to comment.