]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # cassandra Cassandra | |
4 | # | |
5 | # chkconfig: 345 84 25 | |
6 | # | |
7 | # description: Cassandra database node | |
8 | # | |
9 | # processname: cassandra | |
10 | ||
11 | # Source function library | |
12 | . /etc/rc.d/init.d/functions | |
13 | ||
14 | # Get network config | |
15 | . /etc/sysconfig/network | |
16 | ||
17 | # Get service config - may override defaults | |
18 | [ -f /etc/sysconfig/cassandra ] && . /etc/sysconfig/cassandra | |
19 | ||
20 | # Check that networking is up. | |
21 | if is_yes "${NETWORKING}"; then | |
22 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
23 | msg_network_down "cassandra" | |
24 | exit 1 | |
25 | fi | |
26 | else | |
27 | exit 0 | |
28 | fi | |
29 | ||
30 | start() { | |
31 | # Check if the service is already running? | |
32 | if [ -f /var/lock/subsys/cassandra ]; then | |
33 | msg_already_running "cassandra" | |
34 | return | |
35 | fi | |
36 | ||
37 | msg_starting "cassandra" | |
38 | daemon --user cassandra /usr/sbin/cassandra -p /var/run/cassandra/cassandra.pid | |
39 | RETVAL=$? | |
40 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cassandra | |
41 | } | |
42 | ||
43 | ||
44 | stop() { | |
45 | if [ ! -f /var/lock/subsys/cassandra ]; then | |
46 | msg_not_running "cassandra" | |
47 | return | |
48 | fi | |
49 | ||
50 | # Stop daemons. | |
51 | msg_stopping "cassandra" | |
52 | # TODO: Fix it to work it properly with default PLD starting script scheme | |
53 | # I do not know how to make | |
54 | pid=$(cat /var/run/cassandra/cassandra.pid) | |
55 | kill -TERM $pid | |
56 | # 0 - call succeed | |
57 | RETVAL=$? | |
58 | if [ $RETVAL -eq 0 ]; then | |
59 | # Success, giving some time for cassandra to flush. | |
60 | checkpid $pid && sleep 1 | |
61 | checkpid $pid && sleep 3 | |
62 | checkpid $pid && sleep 5 | |
63 | if checkpid $pid; then | |
64 | fail | |
65 | log_failed "cassandra shutdown (timeout after -TERM)" | |
66 | else | |
67 | ok | |
68 | log_success "cassandra shutdown" | |
69 | fi | |
70 | else | |
71 | fail | |
72 | log_failed "cassandra shutdown (signalling error)" | |
73 | fi | |
74 | rm -f /var/lock/subsys/cassandra | |
75 | } | |
76 | ||
77 | condrestart() { | |
78 | if [ ! -f /var/lock/subsys/cassandra ]; then | |
79 | msg_not_running "cassandra" | |
80 | RETVAL=$1 | |
81 | return | |
82 | fi | |
83 | ||
84 | stop | |
85 | start | |
86 | } | |
87 | ||
88 | RETVAL=0 | |
89 | # See how we were called. | |
90 | case "$1" in | |
91 | start) | |
92 | start | |
93 | ;; | |
94 | stop) | |
95 | stop | |
96 | ;; | |
97 | restart) | |
98 | stop | |
99 | start | |
100 | ;; | |
101 | try-restart) | |
102 | condrestart 0 | |
103 | ;; | |
104 | force-reload) | |
105 | condrestart 7 | |
106 | ;; | |
107 | status) | |
108 | # Does not work with /usr/sbin/cassandra for some reason | |
109 | status cassandra | |
110 | ;; | |
111 | *) | |
112 | msg_usage "$0 {start|stop|restart|try-restart|force-reload}" | |
113 | exit 3 | |
114 | esac | |
115 | ||
116 | exit $RETVAL |