3 # MySQL daemon start/stop script.
5 # Debian version. Based on the original by TcX.
9 ${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
11 test -x /usr/sbin/mysqld || exit 0
13 SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
14 CONF=/etc/mysql/my.cnf
15 MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
16 RUNDIR=/var/run/mysqld/
18 # priority can be overriden and "-s" adds output to stderr
19 ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
21 # Safeguard (relative paths, core dumps..)
24 export PATH=/bin:/usr/bin
26 # mysqladmin likes to read /root/.my.cnf. This is usually not what I want
27 # as many admins e.g. only store a password without a username there and
28 # so break my scripts.
29 export HOME=/etc/mysql/
31 ## fetch a particular option from mysql's invocation
33 # usage: void mysqld_get_param option
35 /usr/sbin/mysqld --print-defaults \
42 ## Checks if there is a server running and if so if it is accessible.
44 # check_alive insists on a pingable server
45 # check_dead also fails if there is a lost mysqld in the process list
47 # Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
49 ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
52 pidfile=`mysqld_get_param pid-file`
53 if [ -f "$pidfile" ]; then
54 if ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
57 if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
58 [ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
59 return 0 # EXIT_SUCCESS
61 if [ "$2" = "warn" ]; then
62 /bin/echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
64 return 1 # EXIT_FAILURE
74 # check for config file
75 if [ ! -r $CONF ]; then
76 /bin/echo -e "\nWARNING: $CONF cannot be read. See README.Debian."
78 # check for /var/run/mysqld/ which maybe have only been on a tempfs
79 if [ ! -d $RUNDIR ]; then
80 install --directory --owner=mysql --mode=755 $RUNDIR
83 echo -n "Starting MySQL database server: mysqld"
84 if mysqld_status check_alive nowarn; then
85 echo "...already running."
87 /usr/bin/mysqld_safe > /dev/null 2>&1 &
88 for i in 1 2 3 4 5 6; do
90 if mysqld_status check_alive nowarn ; then break; fi
92 if mysqld_status check_alive warn; then
94 # Now start mysqlcheck or whatever the admin wants.
95 /etc/mysql/debian-start
98 /bin/echo -e "\tPlease take a look at the syslog."
102 if $MYADMIN variables | egrep -q have_bdb.*YES; then
103 /bin/echo "BerkeleyDB is obsolete, see /usr/share/doc/mysql-server/README.Debian.gz" | $ERR_LOGGER -p daemon.info
109 # * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
110 # at least for cron, we can rely on it here, too. (although we have
111 # to specify it explicit as e.g. sudo environments points to the normal
112 # users home and not /root)
113 echo -n "Stopping MySQL database server: mysqld"
114 if ! mysqld_status check_dead nowarn; then
116 shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
118 if [ "$r" -ne 0 ]; then
119 /bin/echo -e -n "...failed.\n$shutdown_out\nKilling MySQL database server by signal: mysqld"
122 for i in 1 2 3 4 5 6 7 8 9 10; do
124 if mysqld_status check_dead nowarn; then server_down=1; break; fi
126 if test -z "$server_down"; then killall -9 mysqld; fi
130 if ! mysqld_status check_dead warn; then
132 echo "Please stop MySQL manually and read /usr/share/doc/mysql-server/README.Debian!"
140 set +e; $SELF stop; set -e
144 'reload'|'force-reload')
145 echo -n "Reloading MySQL database server: mysqld"
151 if mysqld_status check_alive nowarn; then
154 echo "MySQL is stopped."
159 echo "Usage: $SELF start|stop|restart|reload|force-reload"