This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koublad.init
executable file
·197 lines (166 loc) · 2.92 KB
/
koublad.init
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
#
# koublad Start up the Koublad daemon
#
# chkconfig: 2345 55 25
# description: A failover handler for master-slave clusters
#
# processname: koublad
# config: /etc/koublad.conf
# pidfile: /var/run/koublad.pid
### BEGIN INIT INFO
# Provides: koublad
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A failover handler for master-slave clusters
### END INIT INFO
if [ -f /etc/redhat-release ]; then
OSFAMILY=redhat
elif [ -f /etc/os-release ]; then
. /etc/os-release
OSFAMILY=${ID}
else
OSFAMILY=unknown
fi
case ${OSFAMILY} in
debian|ubuntu)
. /lib/lsb/init-functions
DEFAULT_FILE=/etc/default/koublad
;;
redhat)
. /etc/rc.d/init.d/functions
DEFAULT_FILE=/etc/sysconfig/koublad
;;
*)
echo "Distribution not supported"
exit 1
;;
esac
RETVAL=0
ENABLE=0
PID_FILE=/var/run/koublad.pid
KOUBLAD=/usr/sbin/koublad
PROG_NAME=koublad
CONFIG_FILE=/etc/koublad.conf
test -f ${DEFAULT_FILE} && . ${DEFAULT_FILE}
get_pid() {
if [ -f ${PID_FILE} ]; then
cat ${PID_FILE}
fi
}
send_kill() {
# Get pid
PID=`get_pid`
if [ -z "${PID}" ]; then
return 0
fi
# Send SIGTERM
kill -TERM ${PID}
TIMEOUT=15
UNTIL=$((`date +%s`+${TIMEOUT}))
# Wait for process shutdown
while [ -d /proc/${PID} -a `date +%s` -lt ${UNTIL} ]; do
sleep .1
done
# Process is still running, send SIGKILL
if [ -d /proc/${PID} ]; then
kill -KILL ${PID}
fi
return 0
}
start() {
test -x ${KOUBLAD} || exit 5
test -f ${CONFIG_FILE} || exit 6
if [ "${ENABLE}" -ne 1 ]; then
echo "${PROG_NAME} is not enabled. Please check ${DEFAULT_FILE}."
exit 0
fi
case ${OSFAMILY} in
debian|ubuntu)
log_daemon_msg "Starting" "${PROG_NAME}" || true
if ${KOUBLAD} --pid-file ${PID_FILE}; then
log_end_msg 0 || true
RETVAL=0
else
log_end_msg 1 || true
RETVAL=1
fi
return ${RETVAL}
;;
redhat)
echo -n $"Starting ${PROG_NAME}: "
if ${KOUBLAD} --pid-file ${PID_FILE}; then
success
RETVAL=0
else
failure
RETVAL=1
fi
return ${RETVAL}
;;
esac
}
stop() {
case ${OSFAMILY} in
debian|ubuntu)
log_daemon_msg "Stopping" "${PROG_NAME}" || true
if send_kill; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
redhat)
echo -n $"Stopping ${PROG_NAME}: "
if send_kill; then
success
else
failure
fi
;;
esac
echo
}
restart() {
stop
start
}
status() {
PID=`get_pid`
if [ -z "${PID}" -o ! -d /proc/${PID} ]; then
echo "${PROG_NAME} is not running"
return 1
else
echo "${PROG_NAME} is running (PID ${PID})"
return 0
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
restart
;;
status)
if status; then
RETVAL=0
else
RETVAL=2
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
RETVAL=2
esac
exit $RETVAL