2012-01-23 12:20:16 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
2020-04-26 09:41:21 +02:00
|
|
|
# Provides: mariadb
|
2012-01-23 12:20:16 +01:00
|
|
|
# Required-Start: $remote_fs $syslog
|
|
|
|
# Required-Stop: $remote_fs $syslog
|
|
|
|
# Should-Start: $network $named $time
|
|
|
|
# Should-Stop: $network $named $time
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Start and stop the mysql database server daemon
|
2020-06-11 00:39:11 +02:00
|
|
|
# Description: Controls the main MariaDB database server daemon "mariadbd"
|
2012-01-23 12:20:16 +01:00
|
|
|
# and its wrapper script "mysqld_safe".
|
|
|
|
### END INIT INFO
|
|
|
|
#
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
|
|
|
|
|
2020-06-11 00:39:11 +02:00
|
|
|
test -x /usr/sbin/mariadbd || exit 0
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
Misc Debian/Salsa-CI fixes (#2299)
* Deb: Handle codename 'n/a' from Debian Sid properly and autobake-deb cleanup
This fixes autobake-deb.sh builds on Sid which was visible as 4 failing
build steps on Salsa-CI.
- In Sid the LSBNAME might evaluate to 'n/a', so accept it as 'Sid' to
fix builds that failed with error:
Error - unknown release codename n/a
- Refactor list to have Ubuntu versions first, then Debian, and as last
the special case of Debian Sid
- Fix minor syntax issues detected by Shellcheck
Also remove useless DEB_HOST_ARCH_CPU check from debian/rules:
* It was never in effect as the 'sed' in autobake-deb.sh cleared it anyway
* The variable name was wrong and always empty
* If variable would have been correct, logic was still reversed
- Define 3h timeout as the default 1h timeout on Gitlab.com (and others)
is usually not enough for initial (uncached) MariaDB builds.
- Replace Buster to Bookworm/Sid upgrade testing with upgrade inside Buster
testing as direct upgrades from Stretch to Bullseye and Buster to Bookworm
are no longer possible due to:
Bug#993755: libcrypt.so.1: cannot open shared object file when
upgrading from Stretch to Sid (https://bugs.debian.org/993755)
- Stop ignoring MariaDB.org 10.6 to this version upgrade testing failures
to reveal bug MDEV-28640. Originally this step was failing as the uring
dependencies in upstream builders lagged behind and there was nothing
that needed work, only time time to resolve. Now there is an actual bug
in packaging that should be visible as a CI failure.
- Stop testing for 'service mysql status' on systems that upgraded from
MySQL 8.0 to MariaDB.org vended 10.6. Due to some unidentified debian/control
changes in 10.6 on upstream the upgrade is no longer compatible in
a way that would maintain the init.d script with name 'mysql'.
- Fix typos where mergers had changed occurrences of 10.5 to 10.6 while
they intentionally need to be exactly 10.5, otherwise the meaning
changes.
- Align autopkgtest code with downstream official Debian packaging one.
This is change is safe on a stable branch because is only affects builds
and testing, not any actual usage of MariaDB 10.6.
- Standardize on using capitalized 'YES' in CMake build options
(instead of 'yes' or mixed case)
- Add some comments to better document debian/rules
- Fix typo in Lintian overrides
Ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/mariadb-10.6/+bug/1970634
MariaDB ticket: https://jira.mariadb.org/browse/MDEV-25633
When built with LTO on Ubuntu, MariaDB does not catch an exception when
the uring initialization fails due to a low RLIMIT_MEMLOCK value.
This commit amends the commit 0609b345554f9a148e165c497aadbe368e0900aa
to be identical to the one done downstream in Debian:
https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/8d20ca979cf422d3a507283b86c2547d78559179
This way both the inline comments and 'git blame' for this section will
show properly why this is needed, and the fix is one that is fully tested
on Debian and Ubuntu.
Also having this section fully identical in upstream MariaDB and downstream
Debian will make the packaging maintenance easier as 'diff` runs on this
file will not flag this as a difference anymore.
In MDEV-28640 the init script failed to stop/start the MariaDB server
due to missing mysqladmin on the system. This was however very hard to
spot from the console output.
Add an explicit check for the binary the script depends on, and fail
verbosely if the dependency is missing.
2022-11-11 08:51:34 +01:00
|
|
|
SELF=$(cd "$(dirname $0)"; pwd -P)/$(basename $0)
|
2016-10-09 22:39:01 +02:00
|
|
|
|
Misc Debian/Salsa-CI fixes (#2299)
* Deb: Handle codename 'n/a' from Debian Sid properly and autobake-deb cleanup
This fixes autobake-deb.sh builds on Sid which was visible as 4 failing
build steps on Salsa-CI.
- In Sid the LSBNAME might evaluate to 'n/a', so accept it as 'Sid' to
fix builds that failed with error:
Error - unknown release codename n/a
- Refactor list to have Ubuntu versions first, then Debian, and as last
the special case of Debian Sid
- Fix minor syntax issues detected by Shellcheck
Also remove useless DEB_HOST_ARCH_CPU check from debian/rules:
* It was never in effect as the 'sed' in autobake-deb.sh cleared it anyway
* The variable name was wrong and always empty
* If variable would have been correct, logic was still reversed
- Define 3h timeout as the default 1h timeout on Gitlab.com (and others)
is usually not enough for initial (uncached) MariaDB builds.
- Replace Buster to Bookworm/Sid upgrade testing with upgrade inside Buster
testing as direct upgrades from Stretch to Bullseye and Buster to Bookworm
are no longer possible due to:
Bug#993755: libcrypt.so.1: cannot open shared object file when
upgrading from Stretch to Sid (https://bugs.debian.org/993755)
- Stop ignoring MariaDB.org 10.6 to this version upgrade testing failures
to reveal bug MDEV-28640. Originally this step was failing as the uring
dependencies in upstream builders lagged behind and there was nothing
that needed work, only time time to resolve. Now there is an actual bug
in packaging that should be visible as a CI failure.
- Stop testing for 'service mysql status' on systems that upgraded from
MySQL 8.0 to MariaDB.org vended 10.6. Due to some unidentified debian/control
changes in 10.6 on upstream the upgrade is no longer compatible in
a way that would maintain the init.d script with name 'mysql'.
- Fix typos where mergers had changed occurrences of 10.5 to 10.6 while
they intentionally need to be exactly 10.5, otherwise the meaning
changes.
- Align autopkgtest code with downstream official Debian packaging one.
This is change is safe on a stable branch because is only affects builds
and testing, not any actual usage of MariaDB 10.6.
- Standardize on using capitalized 'YES' in CMake build options
(instead of 'yes' or mixed case)
- Add some comments to better document debian/rules
- Fix typo in Lintian overrides
Ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/mariadb-10.6/+bug/1970634
MariaDB ticket: https://jira.mariadb.org/browse/MDEV-25633
When built with LTO on Ubuntu, MariaDB does not catch an exception when
the uring initialization fails due to a low RLIMIT_MEMLOCK value.
This commit amends the commit 0609b345554f9a148e165c497aadbe368e0900aa
to be identical to the one done downstream in Debian:
https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/8d20ca979cf422d3a507283b86c2547d78559179
This way both the inline comments and 'git blame' for this section will
show properly why this is needed, and the fix is one that is fully tested
on Debian and Ubuntu.
Also having this section fully identical in upstream MariaDB and downstream
Debian will make the packaging maintenance easier as 'diff` runs on this
file will not flag this as a difference anymore.
In MDEV-28640 the init script failed to stop/start the MariaDB server
due to missing mysqladmin on the system. This was however very hard to
spot from the console output.
Add an explicit check for the binary the script depends on, and fail
verbosely if the dependency is missing.
2022-11-11 08:51:34 +01:00
|
|
|
if [ -f /usr/bin/mariadb-admin ]
|
|
|
|
then
|
|
|
|
MYADMIN="/usr/bin/mariadb-admin --defaults-file=/etc/mysql/debian.cnf"
|
|
|
|
elif [ -f /usr/bin/mysqladmin ]
|
|
|
|
then
|
|
|
|
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
|
|
|
|
else
|
|
|
|
log_failure_msg "Command mariadb-admin/mysqladmin not found! This SysV init script depends on it."
|
|
|
|
exit -1
|
|
|
|
fi
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2022-12-16 16:51:38 +01:00
|
|
|
if [ ! -x /usr/bin/mariadbd-safe ]
|
|
|
|
then
|
|
|
|
log_failure_msg "/usr/bin/mariadbd-safe not found or executable! This SysV init script depends on it."
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2017-11-15 05:37:32 +01:00
|
|
|
# priority can be overridden and "-s" adds output to stderr
|
2020-04-26 09:41:21 +02:00
|
|
|
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mariadb -i"
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2016-10-09 22:39:01 +02:00
|
|
|
if [ -f /etc/default/mysql ]; then
|
|
|
|
. /etc/default/mysql
|
|
|
|
fi
|
|
|
|
|
2020-04-26 09:41:21 +02:00
|
|
|
# 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
|
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
# Safeguard (relative paths, core dumps..)
|
|
|
|
cd /
|
|
|
|
umask 077
|
|
|
|
|
|
|
|
# mysqladmin likes to read /root/.my.cnf. This is usually not what I want
|
|
|
|
# as many admins e.g. only store a password without a username there and
|
|
|
|
# so break my scripts.
|
|
|
|
export HOME=/etc/mysql/
|
|
|
|
|
|
|
|
## Fetch a particular option from mysql's invocation.
|
|
|
|
#
|
2020-06-11 00:39:11 +02:00
|
|
|
# Usage: void mariadbd_get_param option
|
|
|
|
mariadbd_get_param() {
|
|
|
|
/usr/sbin/mariadbd --print-defaults \
|
2016-10-09 22:39:01 +02:00
|
|
|
| tr " " "\n" \
|
|
|
|
| grep -- "--$1" \
|
|
|
|
| tail -n 1 \
|
|
|
|
| cut -d= -f2
|
2012-01-23 12:20:16 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 00:39:11 +02:00
|
|
|
## Do some sanity checks before even trying to start mariadbd.
|
2012-01-23 12:20:16 +01:00
|
|
|
sanity_checks() {
|
|
|
|
# check for config file
|
|
|
|
if [ ! -r /etc/mysql/my.cnf ]; then
|
|
|
|
log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
|
|
|
|
echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check for diskspace shortage
|
2020-06-11 00:39:11 +02:00
|
|
|
datadir=`mariadbd_get_param datadir`
|
2023-03-13 10:56:53 +01:00
|
|
|
# As preset blocksize of GNU df is 1024 then available bytes is $df_available_blocks * 1024
|
|
|
|
# 4096 blocks is then lower than 4 MB
|
|
|
|
df_available_blocks=`LC_ALL=C BLOCKSIZE= df --output=avail "$datadir" | tail -n 1`
|
|
|
|
if [ "$df_available_blocks" -lt "4096" ]; then
|
2012-01-23 12:20:16 +01:00
|
|
|
log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
|
|
|
|
echo "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Checks if there is a server running and if so if it is accessible.
|
|
|
|
#
|
|
|
|
# check_alive insists on a pingable server
|
2020-06-11 00:39:11 +02:00
|
|
|
# check_dead also fails if there is a lost mariadbd in the process list
|
2012-01-23 12:20:16 +01:00
|
|
|
#
|
2020-06-11 00:39:11 +02:00
|
|
|
# Usage: boolean mariadbd_status [check_alive|check_dead] [warn|nowarn]
|
|
|
|
mariadbd_status () {
|
2016-10-09 22:39:01 +02:00
|
|
|
ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
|
|
|
|
|
|
|
|
ps_alive=0
|
2020-06-11 00:39:11 +02:00
|
|
|
pidfile=`mariadbd_get_param pid-file`
|
2016-10-09 22:39:01 +02:00
|
|
|
if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
|
|
|
|
|
|
|
|
if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
|
|
|
|
[ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
|
|
|
|
return 0 # EXIT_SUCCESS
|
|
|
|
else
|
|
|
|
if [ "$2" = "warn" ]; then
|
|
|
|
echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
|
2012-01-23 12:20:16 +01:00
|
|
|
fi
|
2016-10-09 22:39:01 +02:00
|
|
|
return 1 # EXIT_FAILURE
|
|
|
|
fi
|
2012-01-23 12:20:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# main()
|
|
|
|
#
|
|
|
|
|
|
|
|
case "${1:-''}" in
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
'start')
|
2016-10-09 22:39:01 +02:00
|
|
|
sanity_checks;
|
|
|
|
# Start daemon
|
2020-06-11 00:39:11 +02:00
|
|
|
log_daemon_msg "Starting MariaDB database server" "mariadbd"
|
|
|
|
if mariadbd_status check_alive nowarn; then
|
2016-10-09 22:39:01 +02:00
|
|
|
log_progress_msg "already running"
|
|
|
|
log_end_msg 0
|
|
|
|
else
|
|
|
|
# Could be removed during boot
|
2020-04-26 09:41:21 +02:00
|
|
|
test -e /run/mysqld || install -m 755 -o mysql -g root -d /run/mysqld
|
2016-10-09 22:39:01 +02:00
|
|
|
|
|
|
|
# Start MariaDB!
|
2022-12-16 16:51:38 +01:00
|
|
|
/usr/bin/mariadbd-safe "${@:2}" 2>&1 >/dev/null | $ERR_LOGGER &
|
2016-10-09 22:39:01 +02:00
|
|
|
|
|
|
|
for i in $(seq 1 "${MYSQLD_STARTUP_TIMEOUT:-30}"); do
|
|
|
|
sleep 1
|
2020-06-11 00:39:11 +02:00
|
|
|
if mariadbd_status check_alive nowarn ; then break; fi
|
2016-10-09 22:39:01 +02:00
|
|
|
log_progress_msg "."
|
|
|
|
done
|
2020-06-11 00:39:11 +02:00
|
|
|
if mariadbd_status check_alive warn; then
|
2016-10-09 22:39:01 +02:00
|
|
|
log_end_msg 0
|
|
|
|
# Now start mysqlcheck or whatever the admin wants.
|
|
|
|
output=$(/etc/mysql/debian-start)
|
|
|
|
if [ -n "$output" ]; then
|
|
|
|
log_action_msg "$output"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
log_end_msg 1
|
|
|
|
log_failure_msg "Please take a look at the syslog"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
'stop')
|
2016-10-09 22:39:01 +02:00
|
|
|
# * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
|
|
|
|
# at least for cron, we can rely on it here, too. (although we have
|
|
|
|
# to specify it explicit as e.g. sudo environments points to the normal
|
|
|
|
# users home and not /root)
|
2020-06-11 00:39:11 +02:00
|
|
|
log_daemon_msg "Stopping MariaDB database server" "mariadbd"
|
|
|
|
if ! mariadbd_status check_dead nowarn; then
|
2016-10-09 22:39:01 +02:00
|
|
|
set +e
|
|
|
|
shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
|
|
|
|
set -e
|
|
|
|
if [ "$r" -ne 0 ]; then
|
|
|
|
log_end_msg 1
|
|
|
|
[ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
|
2020-06-11 00:39:11 +02:00
|
|
|
log_daemon_msg "Killing MariaDB database server by signal" "mariadbd"
|
|
|
|
killall -15 mariadbd
|
2016-10-09 22:39:01 +02:00
|
|
|
server_down=
|
|
|
|
for i in `seq 1 600`; do
|
|
|
|
sleep 1
|
2020-06-11 00:39:11 +02:00
|
|
|
if mariadbd_status check_dead nowarn; then server_down=1; break; fi
|
2016-10-09 22:39:01 +02:00
|
|
|
done
|
2020-06-11 00:39:11 +02:00
|
|
|
if test -z "$server_down"; then killall -9 mariadbd; fi
|
2016-10-09 22:39:01 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-06-11 00:39:11 +02:00
|
|
|
if ! mariadbd_status check_dead warn; then
|
2016-10-09 22:39:01 +02:00
|
|
|
log_end_msg 1
|
2022-04-11 10:32:26 +02:00
|
|
|
log_failure_msg "Please stop MariaDB manually and read /usr/share/doc/mariadb-server/README.Debian.gz!"
|
2016-10-09 22:39:01 +02:00
|
|
|
exit -1
|
|
|
|
else
|
|
|
|
log_end_msg 0
|
|
|
|
fi
|
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
'restart')
|
2016-10-09 22:39:01 +02:00
|
|
|
set +e; $SELF stop; set -e
|
|
|
|
shift
|
|
|
|
$SELF start "${@}"
|
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
'reload'|'force-reload')
|
2020-06-11 00:39:11 +02:00
|
|
|
log_daemon_msg "Reloading MariaDB database server" "mariadbd"
|
2016-10-09 22:39:01 +02:00
|
|
|
$MYADMIN reload
|
|
|
|
log_end_msg 0
|
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
'status')
|
2020-06-11 00:39:11 +02:00
|
|
|
if mariadbd_status check_alive nowarn; then
|
2016-10-09 22:39:01 +02:00
|
|
|
log_action_msg "$($MYADMIN version)"
|
|
|
|
else
|
|
|
|
log_action_msg "MariaDB is stopped."
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
;;
|
2015-09-15 22:27:04 +02:00
|
|
|
|
2020-04-26 09:41:21 +02:00
|
|
|
'bootstrap')
|
|
|
|
# Bootstrap the cluster, start the first node
|
|
|
|
# that initiates the cluster
|
2020-06-11 00:39:11 +02:00
|
|
|
log_daemon_msg "Bootstrapping the cluster" "mariadbd"
|
2020-04-26 09:41:21 +02:00
|
|
|
$SELF start "${@:2}" --wsrep-new-cluster
|
|
|
|
;;
|
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
*)
|
2016-10-09 22:39:01 +02:00
|
|
|
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
|
|
|
|
exit 1
|
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
esac
|