Skip to content

Commit

Permalink
Deb: Add support for legacy init systems again
Browse files Browse the repository at this point in the history
Partially reverts commit a4cc6fb.

While all current versions of Linux have systemd, support for traditional
init.d is still needed e.g. on Linux subsystem on Windows, kFreeBSD and
special variants of Debian/Ubuntu that for other reasons don't have
systemd.

Thus, re-introduce the init file that was remove, but this time with
then name 'mariadb'.

Supporting traditional sysv init in paraller with systemd is easy, since
Debian has facilities for it.

Also simplify and update salsa-ci.yml install/upgrade testing works
for all previous MariaDB and MySQL releases without any excess quirks.

Note that in fresh installs the salsa-ci.yml needs to run command
'service mariadb status' to control the service, while on upgrades
it is enough to run 'service mysql status', since the init.d/mysql
file is left behind from previous install, along with some other
config files such as /etc/default/mysql and /etc/mysql/* stuff.
  • Loading branch information
ottok committed May 16, 2020
1 parent 69077de commit 764dd39
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 64 deletions.
7 changes: 6 additions & 1 deletion debian/additions/debian-start
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# This script is executed by "/etc/init.d/mysql" on every (re)start.
# This script is executed by "/etc/init.d/mariadb" on every (re)start.
#
# Changes to this file will be preserved when updating the Debian package.
#
Expand All @@ -9,10 +9,15 @@

source /usr/share/mysql/debian-start.inc.sh

# Read default/mysql first and then default/mariadb just like the init.d file does
if [ -f /etc/default/mysql ]; then
. /etc/default/mysql
fi

if [ -f /etc/default/mariadb ]; then
. /etc/default/mariadb
fi

MYSQL="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf"
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# Don't run full mysql_upgrade on every server restart, use --version-check to do it only once
Expand Down
1 change: 0 additions & 1 deletion debian/mariadb-server-10.5.install
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
debian/additions/debian-start etc/mysql
debian/additions/debian-start.inc.sh usr/share/mysql
debian/additions/echo_stderr usr/share/mysql
debian/additions/mysql.init usr/share/mysql
debian/additions/mysqld_safe_syslog.cnf etc/mysql/conf.d
debian/additions/source_mariadb-10.5.py usr/share/apport/package-hooks
etc/apparmor.d/usr.sbin.mysqld
Expand Down
6 changes: 3 additions & 3 deletions debian/mariadb-server-10.5.logcheck.ignore.paranoid
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/etc/init.d/mysql\[[0-9]+\]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mysql\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mariadb\[[0-9]+\]: Check that mysqld is running and that the socket: '/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mariadb\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/mysql/debian-start\[[0-9]+\]: Checking for crashed MySQL tables\.$
mysqld\[[0-9]+\]: $
mysqld\[[0-9]+\]: Version: .* socket: '/var/run/mysqld/mysqld.sock' port: 3306$
mysqld\[[0-9]+\]: Version: .* socket: '/run/mysqld/mysqld.sock' port: 3306$
mysqld\[[0-9]+\]: Warning: Ignoring user change to 'mysql' because the user was set to 'mysql' earlier on the command line$
mysqld_safe\[[0-9]+\]: started$
usermod\[[0-9]+\]: change user `mysql' GID from `([0-9]+)' to `\1'$
Expand Down
6 changes: 3 additions & 3 deletions debian/mariadb-server-10.5.logcheck.ignore.server
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/etc/init.d/mysql\[[0-9]+\]: [0-9]+ processes alive and '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mysql\[[0-9]+\]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mysql\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mariadb\[[0-9]+\]: [0-9]+ processes alive and '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mariadb\[[0-9]+\]: Check that mysqld is running and that the socket: '/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mariadb\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/mysql/debian-start\[[0-9]+\]: Checking for crashed MySQL tables\.$
mysqld\[[0-9]+\]: ?$
mysqld\[[0-9]+\]: .*InnoDB: Shutdown completed
Expand Down
6 changes: 3 additions & 3 deletions debian/mariadb-server-10.5.logcheck.ignore.workstation
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/etc/init.d/mysql\[[0-9]+\]: [0-9]+ processes alive and '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mysql\[[0-9]+\]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mysql\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mariadb\[[0-9]+\]: [0-9]+ processes alive and '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/init.d/mariadb\[[0-9]+\]: Check that mysqld is running and that the socket: '/run/mysqld/mysqld.sock' exists\!$
/etc/init.d/mariadb\[[0-9]+\]: '/usr/bin/mysqladmin --defaults-(extra-)?file=/etc/mysql/debian.cnf ping' resulted in$
/etc/mysql/debian-start\[[0-9]+\]: Checking for crashed MySQL tables\.$
mysqld\[[0-9]+\]: ?$
mysqld\[[0-9]+\]: .*InnoDB: Shutdown completed
Expand Down
20 changes: 17 additions & 3 deletions debian/additions/mysql.init → debian/mariadb-server-10.5.mariadb.init
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: mysql
# Provides: mariadb
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $named $time
Expand All @@ -26,12 +26,19 @@ SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"

# priority can be overridden and "-s" adds output to stderr
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mariadb -i"

if [ -f /etc/default/mysql ]; then
. /etc/default/mysql
fi

# Also source default/mariadb in case the installation was upgraded from
# packages originally installed from MariaDB.org repositories, which have
# had support for reading /etc/default/mariadb since March 2016.
if [ -f /etc/default/mariadb ]; then
. /etc/default/mariadb
fi

# Safeguard (relative paths, core dumps..)
cd /
umask 077
Expand Down Expand Up @@ -108,7 +115,7 @@ case "${1:-''}" in
log_end_msg 0
else
# Could be removed during boot
test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
test -e /run/mysqld || install -m 755 -o mysql -g root -d /run/mysqld

# Start MariaDB!
/usr/bin/mysqld_safe "${@:2}" 2>&1 >/dev/null | $ERR_LOGGER &
Expand Down Expand Up @@ -186,6 +193,13 @@ case "${1:-''}" in
fi
;;

'bootstrap')
# Bootstrap the cluster, start the first node
# that initiates the cluster
log_daemon_msg "Bootstrapping the cluster" "mysqld"
$SELF start "${@:2}" --wsrep-new-cluster
;;

*)
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
exit 1
Expand Down
46 changes: 36 additions & 10 deletions debian/mariadb-server-10.5.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,42 @@ ERR_LOGGER="logger -p daemon.err -t mariadb-server-$MAJOR_VER.postinst -i"
# the install, rather than failing silently and leaving a broken install.
set -o pipefail

invoke() {
systemctl $1 mysql
}

case "$1" in
configure)
# This is needed because mysql_install_db removes the pid file in /var/run
# This is needed because mysql_install_db removes the pid file in /run
# and because changed configuration options should take effect immediately.
# In case the server wasn't running at all it should be ok if the stop
# script fails. I can't tell at this point because of the cleaned /var/run.
set +e; invoke stop; set -e
# script fails. I can't tell at this point because of the cleaned /run.
set +e; invoke-rc.d mariadb stop; set -e

# An existing /etc/init.d/mysql might be on the system if there was a
# previous MySQL or MariaDB installation, since /etc/init.d files are
# considered config files and stay around even after the package is removed.
#
# The install step of this package adds a new /etc/init.d/mariadb file. As
# we also want to ensure that there are no old (and potentially outdated)
# versions of /etc/init.d/mysql we simply replace it using a copy of the
# latest 'mariadb' file. This has also the added benefit that anything that
# invokes traditional sysv init with either 'mysql' or 'mariadb' will end up
# controlling this newly installed MariaDB, and thus we maintain better
# backwards compatiblity.
#
# Note that the 'Provides' line is also updated to avoid 'insserv' exiting
# on failure (when it is run by update-rc.d) because of duplicate service
# names.
if [ -f "/etc/init.d/mysql" ] && [ -f "/etc/init.d/mariadb" ]
then
# Copy init file and rename the service name and filename on the fly
sed 's/Provides: mariadb/Provides: mysql/g' /etc/init.d/mariadb > /etc/init.d/mysql
# NOTE: Number of spaces/tabs is important here!
# Confirm if the sed worked
if ! grep --quiet "Provides: mysql" /etc/init.d/mysql
then
# If not, then delete the file to avoid failures later on
rm -f /etc/init.d/mysql
echo "Warning! Failed creating a mysql named copy of mariadb init.d file"
fi
fi

mysql_statedir=/usr/share/mysql
mysql_datadir=/var/lib/mysql
Expand Down Expand Up @@ -126,7 +151,7 @@ EOF

# initiate databases. Output is not allowed by debconf :-(
# This will fail if we are upgrading an existing database; in this case
# mysql_upgrade, called from the /etc/init.d/mysql start script, will
# mysql_upgrade, called from the /etc/init.d/mariadb start script, will
# handle things.
# Debian: beware of the bashisms...
# Debian: can safely run on upgrades with existing databases
Expand Down Expand Up @@ -187,8 +212,9 @@ EOF
triggered)
if [ -x "$(command -v systemctl)" ]; then
systemctl daemon-reload
else
invoke-rc.d mariadb restart
fi
invoke restart
;;

*)
Expand All @@ -199,7 +225,7 @@ esac

db_stop # in case invoke failes

# dh_systemd_start doesn't emit anything since we still ship /etc/init.d/mysql.
# dh_systemd_start doesn't emit anything since we still ship /etc/init.d/mariadb.
# Thus MariaDB server is started via init.d script, which in turn redirects to
# systemctl. If we upgrade from MySQL mysql.service may be masked, which also
# means init.d script is disabled. Unmask mysql service explicitly.
Expand Down
30 changes: 19 additions & 11 deletions debian/mariadb-server-10.5.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ 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
systemctl stop mysql
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 mariadb 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
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then
Expand Down Expand Up @@ -74,7 +82,7 @@ if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ]; then
# /var/lib/mysql is a mount point
rmdir --ignore-fail-on-non-empty /var/lib/mysql || true
fi
rm -rf /var/run/mysqld # this directory is created by the init script, don't leave behind
rm -rf /run/mysqld # this directory is created by the init script, don't leave behind
userdel mysql || true
fi

Expand Down
8 changes: 4 additions & 4 deletions debian/mariadb-server-10.5.preinst
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ stop_server() {
if ! pgrep -x --ns $$ mysqld > /dev/null; then return; fi

set +e
systemctl stop mysql
invoke-rc.d mariadb 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
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ override_dh_systemd_enable:
# Start mysql at sequence number 19 before 20 where apache, proftpd etc gets
# started which might depend on a running database server.
override_dh_installinit-arch:
#dh_installinit --name=mysql -- defaults 19 21
dh_installinit --name=mariadb --no-start -- defaults 19 21
dh_systemd_start --restart-after-upgrade


Expand Down
Loading

0 comments on commit 764dd39

Please sign in to comment.