--- mysql-dfsg-4.0.20.orig/debian/mysql-server.init +++ mysql-dfsg-4.0.20/debian/mysql-server.init @@ -0,0 +1,118 @@ +#!/bin/sh +# +# MySQL daemon start/stop script. +# +# Debian version. Based on the original by TcX. +# +set -e +set -u +${DEBIAN_SCRIPT_DEBUG:+ set -v -x} + +test -x /usr/sbin/mysqld || exit 0 + +SELF=$(cd $(dirname $0); pwd -P)/$(basename $0) +CONF=/etc/mysql/my.cnf +MYADMIN="/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf" + +# priority can be overriden and "-s" adds output to stderr +ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i" + +# Safeguard (relative paths, core dumps..) +cd / +umask 077 +export PATH=/bin:/usr/bin + +# 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/ + + +# "if" considers exit(0) as true so we can just pass mysqladmins exit code here. +# If mysqladmin does not exist the return code will be silently set to !0, too. +is_mysqld_alive () { + s=`$MYADMIN ping 2>&1`; rc=$? + if [ $rc != 0 ]; then + echo "'$MYADMIN ping' resulted in" | $ERR_LOGGER -p daemon.debug + echo "$s" | $ERR_LOGGER -p daemon.debug + fi + return $rc +} + +case "${1:-''}" in + 'start') + # check for config file + if [ ! -r /etc/mysql/my.cnf ]; then + echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian." + fi + # Start daemon + echo -n "Starting MySQL database server: mysqld" + /usr/bin/mysqld_safe > /dev/null 2>&1 & + for i in 1 2 3 4 5 6; do + sleep 1 + if is_mysqld_alive; then break; fi + done + if is_mysqld_alive; then + echo "." + # Now start mysqlcheck or whatever the admin wants. + /etc/mysql/debian-start + else + echo "...failed." + /bin/echo -e "\tPlease take a look at the syslog." + fi + ;; + + 'stop') + # * 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) + echo -n "Stopping MySQL database server: mysqld" + if is_mysqld_alive; then + set +e + $MYADMIN shutdown + r=$? + set -e + if [ "$r" -ne 0 ]; then + echo "...failed" + echo -n "Killing MySQL database server by signal: mysqld" + killall -15 mysqld + server_down= + for i in 1 2 3 4 5 6 7 8 9 10; do + sleep 1 + if is_mysqld_alive; then : ; else server_down=1; break; fi + done + if -z "$server_down"; then killall -9 mysqld; fi + fi + fi + + if is_mysqld_alive; then + echo "...failed." + echo "Please stop the daemon yourself!" + exit -1 + else + echo "." + fi + ;; + + 'restart') + set +e; $SELF stop; set -e + $SELF start + ;; + + 'reload'|'force-reload') + echo -n "Reloading MySQL database server: mysqld" + $MYADMIN reload + echo "." + ;; + + 'status') + $MYADMIN version + ;; + + *) + echo "Usage: $SELF start|stop|restart|reload|force-reload" + exit 1 + ;; +esac +