blob: ba7cefd9ec58a5785aed1b35ea864888a68d6231 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/bin/bash
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
export HOME=/etc/mysql
cd /
umask 077
mysqld_get_param() {
/usr/sbin/mysqld --print-defaults \
| tr " " "\n" \
| grep -- "--$1" \
| tail -n 1 \
| cut -d= -f2
}
## Checks if there is a server running and if so if it is accessible.
#
# check_alive insists on a pingable server
# check_dead also fails if there is a lost mysqld in the process list
#
# Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
mysqld_status () {
ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
ps_alive=0
pidfile=`mysqld_get_param pid-file`
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
fi
return 1 # EXIT_FAILURE
fi
}
start() {
test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
/usr/bin/mysqld_safe > /dev/null 2>&1 &
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
sleep 1
if mysqld_status check_alive nowarn ; then break; fi
done
if mysqld_status check_alive warn; then
output=$(/etc/mysql/debian-start)
[ -n "$output" ] && echo "$output"
else
echo "Please take a look at the syslog"
fi
}
stop() {
shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
if [ "$r" -ne 0 ]; then
echo "mysqld shutdown failed: $shutdown_out"
echo "killing by signal"
pidfile=`mysqld_get_param pid-file`
if [ -f "$pidfile" ]; then
pkill mysqld
fi
fi
}
refresh() {
$MYADMIN reload
}
case "$1" in
start) start;;
stop) stop;;
refresh) refresh;;
esac
|