]>
Commit | Line | Data |
---|---|---|
a207031c ER |
1 | #!/bin/sh |
2 | # | |
3 | # pt-kill This shell script takes care of starting and stopping the pt-kill services. | |
4 | # | |
5 | # chkconfig: 345 60 40 | |
6 | # | |
7 | # description: pt-kill stops long running MySQL queries | |
8 | # processname: pt-kill | |
9 | ||
10 | # Source function library | |
11 | . /etc/rc.d/init.d/functions | |
12 | ||
13 | # Get network config | |
14 | . /etc/sysconfig/network | |
15 | ||
16 | # Check that networking is up. | |
17 | if is_yes "${NETWORKING}"; then | |
18 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
19 | msg_network_down "pt-kill" | |
20 | exit 1 | |
21 | fi | |
22 | else | |
23 | exit 0 | |
24 | fi | |
25 | ||
26 | config=/etc/percona-toolkit/pt-kill.conf | |
9a55bcde ER |
27 | sentinel=/var/run/percona-toolkit/pt-kill.sentinel |
28 | pidfile=/var/run/percona-toolkit/pt-kill.pid | |
29 | user=percona-toolkit | |
210a69e2 ER |
30 | # use "empty" DSN, so it uses my.cnf settings |
31 | dsn=';' | |
a207031c ER |
32 | |
33 | # Get service config - may override defaults | |
34 | [ -f /etc/sysconfig/pt-kill ] && . /etc/sysconfig/pt-kill | |
35 | ||
36 | start() { | |
37 | # Check if the service is already running? | |
38 | if [ -f /var/lock/subsys/pt-kill ]; then | |
39 | msg_already_running "pt-kill" | |
40 | return | |
41 | fi | |
42 | ||
43 | msg_starting "pt-kill" | |
44 | # FIXME: instead of removing, fix stop process | |
45 | rm -f $sentinel | |
016f37e7 | 46 | # use RC_LOGGING=no, because we need to escape ";" from shell |
bfd200a0 | 47 | # NOTE: disable --redirfds to be able to see connect errors |
016f37e7 | 48 | RC_LOGGING=no \ |
349c5c33 | 49 | daemon --user $user --redirfds \ |
210a69e2 | 50 | /usr/bin/pt-kill --config $config --daemonize --pid $pidfile --sentinel $sentinel "$dsn" |
a207031c | 51 | RETVAL=$? |
349c5c33 ER |
52 | |
53 | # workaround for lack of exit status check: | |
54 | # https://bugs.launchpad.net/percona-toolkit/+bug/1314500 | |
55 | [ ! -f "$pidfile" -a $RETVAL = 0 ] && RETVAL=1 | |
56 | ||
a207031c ER |
57 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pt-kill |
58 | } | |
59 | ||
60 | stop() { | |
61 | if [ ! -f /var/lock/subsys/pt-kill ]; then | |
62 | msg_not_running "pt-kill" | |
63 | return | |
64 | fi | |
65 | ||
66 | # Stop daemons. | |
67 | msg_stopping "pt-kill" | |
68 | run_cmd --user $user "pt-kill" /usr/bin/pt-kill --config $config --stop --sentinel $sentinel | |
69 | # FIXME: wait for sentinel and remove it | |
70 | rm -f /var/lock/subsys/pt-kill | |
71 | } | |
72 | ||
73 | condrestart() { | |
74 | if [ ! -f /var/lock/subsys/pt-kill ]; then | |
75 | msg_not_running "pt-kill" | |
76 | RETVAL=$1 | |
77 | return | |
78 | fi | |
79 | ||
80 | stop | |
81 | start | |
82 | } | |
83 | ||
84 | RETVAL=0 | |
85 | # See how we were called. | |
86 | case "$1" in | |
87 | start) | |
88 | start | |
89 | ;; | |
90 | stop) | |
91 | stop | |
92 | ;; | |
93 | restart) | |
94 | stop | |
95 | start | |
96 | ;; | |
97 | try-restart) | |
98 | condrestart 0 | |
99 | ;; | |
100 | force-reload) | |
101 | condrestart 7 | |
102 | ;; | |
103 | status) | |
104 | status --pidfile $pidfile pt-kill | |
105 | RETVAL=$? | |
106 | ;; | |
107 | *) | |
108 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" | |
109 | exit 3 | |
110 | esac | |
111 | ||
112 | exit $RETVAL |