5
# Required-Start: $remote_fs $syslog
6
# Required-Stop: $remote_fs $syslog
7
# Should-Start: $network $named $time
8
# Should-Stop: $network $named $time
9
# Default-Start: 2 3 4 5
11
# Short-Description: Start and stop the mysql database server daemon
12
# Description: Controls the main MySQL database server daemon "mysqld"
13
# and its wrapper script "mysqld_safe".
18
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
19
PERCONA_PREFIX=/opt/percona/percona-server-5.5
21
test -x "${PERCONA_PREFIX}"/bin/mysqld || exit 0
23
. /lib/lsb/init-functions
25
SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
26
CONF=/etc/mysql/my.cnf
27
MYADMIN="${PERCONA_PREFIX}/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
29
# priority can be overriden and "-s" adds output to stderr
30
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
32
# Safeguard (relative paths, core dumps..)
36
# mysqladmin likes to read /root/.my.cnf. This is usually not what I want
37
# as many admins e.g. only store a password without a username there and
38
# so break my scripts.
39
export HOME=/etc/mysql/
41
## Fetch a particular option from mysql's invocation.
43
# Usage: void mysqld_get_param option
45
"${PERCONA_PREFIX}"/bin/mysqld --print-defaults \
52
## Do some sanity checks before even trying to start mysqld.
54
# check for config file
55
if [ ! -r /etc/mysql/my.cnf ]; then
56
log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
57
echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
60
# check for diskspace shortage
61
datadir=`mysqld_get_param datadir`
62
if LC_ALL=C BLOCKSIZE= df --portability $datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
63
log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
64
echo "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
69
## Checks if there is a server running and if so if it is accessible.
71
# check_alive insists on a pingable server
72
# check_dead also fails if there is a lost mysqld in the process list
74
# Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
76
ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
79
pidfile=`mysqld_get_param pid-file`
80
if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
82
if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
83
[ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
84
return 0 # EXIT_SUCCESS
86
if [ "$2" = "warn" ]; then
87
echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
89
return 1 # EXIT_FAILURE
101
log_daemon_msg "Starting MySQL database server" "mysqld"
102
if mysqld_status check_alive nowarn; then
103
log_progress_msg "already running"
106
"${PERCONA_PREFIX}"/bin/mysqld_safe > /dev/null 2>&1 &
107
# 6s was reported in #352070 to be too few when using ndbcluster
108
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
110
if mysqld_status check_alive nowarn ; then break; fi
113
if mysqld_status check_alive warn; then
115
# Now start mysqlcheck or whatever the admin wants.
116
output=$(/etc/mysql/debian-start)
117
[ -n "$output" ] && log_action_msg "$output"
120
log_failure_msg "Please take a look at the syslog"
126
# * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
127
# at least for cron, we can rely on it here, too. (although we have
128
# to specify it explicit as e.g. sudo environments points to the normal
129
# users home and not /root)
130
log_daemon_msg "Stopping MySQL database server" "mysqld"
131
if ! mysqld_status check_dead nowarn; then
133
shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
135
if [ "$r" -ne 0 ]; then
137
[ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
138
log_daemon_msg "Killing MySQL database server by signal" "mysqld"
141
for i in 1 2 3 4 5 6 7 8 9 10; do
143
if mysqld_status check_dead nowarn; then server_down=1; break; fi
145
if test -z "$server_down"; then killall -9 mysqld; fi
149
if ! mysqld_status check_dead warn; then
151
log_failure_msg "Please stop MySQL manually and read /usr/share/doc/percona-server-server-5.5/README.Debian.gz!"
159
set +e; $SELF stop; set -e
163
'reload'|'force-reload')
164
log_daemon_msg "Reloading MySQL database server" "mysqld"
170
if mysqld_status check_alive nowarn; then
171
log_action_msg "$($MYADMIN version)"
173
log_action_msg "MySQL is stopped."
179
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"