3 ##############################
4 # ctdb: Starts the clustered tdb daemon
8 # description: Starts and stops the clustered tdb daemon
9 # pidfile: /var/run/ctdbd/ctdbd.pid
14 # Required-Start: $network
15 # Required-Stop: $network
18 # Short-Description: start and stop ctdb service
19 # Description: initscript for the ctdb service
22 # Source function library.
23 if [ -f /etc/init.d/functions ] ; then
24 . /etc/init.d/functions
25 elif [ -f /etc/rc.d/init.d/functions ] ; then
26 . /etc/rc.d/init.d/functions
29 [ -f /etc/rc.status ] && {
35 # Avoid using root's TMPDIR
38 [ -z "$CTDB_BASE" ] && {
39 export CTDB_BASE="/etc/ctdb"
42 [ -z "$CTDB_VARDIR" ] && {
43 export CTDB_VARDIR="/var/ctdb"
46 . $CTDB_BASE/functions
50 # check networking is up (for redhat)
51 [ "$NETWORKING" = "no" ] && exit 0
54 export CTDB_INIT_STYLE
56 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
58 if [ "$CTDB_VALGRIND" = "yes" ]; then
61 init_style="$CTDB_INIT_STYLE"
64 build_ctdb_options () {
67 # If the 2nd arg is null then return - don't set anything.
68 # Else if the 3rd arg is set and it doesn't match the 2nd arg
70 [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
77 # For these options we're only passing a value-less flag.
83 # we may quote the value
88 CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
91 [ -z "$CTDB_RECOVERY_LOCK" ] && {
92 echo "No recovery lock specified. Starting CTDB without split brain prevention"
94 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
96 # build up CTDB_OPTIONS variable from optional parameters
97 maybe_set "--logfile" "$CTDB_LOGFILE"
98 maybe_set "--nlist" "$CTDB_NODES"
99 maybe_set "--socket" "$CTDB_SOCKET"
100 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
101 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
102 maybe_set "--dbdir" "$CTDB_DBDIR"
103 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
104 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
105 maybe_set "--transport" "$CTDB_TRANSPORT"
106 maybe_set "-d" "$CTDB_DEBUGLEVEL"
107 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
108 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
109 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
110 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
111 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
112 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
113 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
114 maybe_set "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
115 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
116 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
117 maybe_set "--panic-action" "$CTDB_PANIC_ACTION" "" "'"
123 local TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
125 test x"$TDBTOOL_HAS_CHECK" = x"1" && {
127 # Note tdbtool always exits with 0
129 local OK=`/usr/bin/tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
130 test x"$OK" = x"1" || {
137 /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
144 check_persistent_databases () {
145 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
146 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
147 local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
149 test -z "$ERRCOUNT" && {
152 test x"$ERRCOUNT" != x"0" && {
155 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
156 check_tdb $PDBASE || {
157 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
163 set_ctdb_variables () {
164 # set any tunables from the config file
165 set | grep ^CTDB_SET_ | cut -d_ -f3- |
167 varname=`echo $v | cut -d= -f1`
168 value=`echo $v | cut -d= -f2`
169 ctdb setvar $varname $value || RETVAL=1
177 wait_until_ready () {
178 _timeout="${1:-10}" # default is 10 seconds
181 while ! ctdb ping >/dev/null 2>&1 ; do
182 if [ $_count -ge $_timeout ] ; then
186 _count=$(($_count + 1))
190 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
193 echo -n $"Starting ctdbd service: "
195 ctdb ping >/dev/null 2>&1 && {
196 echo $"CTDB is already running"
202 check_persistent_databases || return $?
204 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
212 eval valgrind -q --log-file=/var/log/ctdb_valgrind \
213 $ctdbd --valgrinding "$CTDB_OPTIONS"
218 eval startproc $ctdbd "$CTDB_OPTIONS"
222 eval $ctdbd "$CTDB_OPTIONS"
224 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
227 eval start-stop-daemon --start --quiet --background \
228 --exec $ctdbd -- "$CTDB_OPTIONS"
233 if [ $RETVAL -eq 0 ] ; then
234 if wait_until_ready ; then
238 pkill -9 -f $ctdbd >/dev/null 2>&1
248 [ $RETVAL -eq 0 ] && success || failure
257 echo -n $"Shutting down ctdbd service: "
258 pkill -0 -f $ctdbd || {
259 echo -n " Warning: ctdbd not running ! "
270 ctdb shutdown >/dev/null 2>&1
273 while pkill -0 -f $ctdbd ; do
275 count=$(($count + 1))
276 [ $count -gt 10 ] && {
277 echo -n $"killing ctdbd "
279 pkill -9 -f $CTDB_BASE/events.d/
284 # re-set the return code to the recorded RETVAL in order
285 # to print the correct status message
290 [ $RETVAL -eq 0 ] && success || failure
291 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
304 echo -n $"Checking for ctdbd service: "
305 ctdb ping >/dev/null 2>&1 || {
307 echo -n " ctdbd not running. "
314 if [ -f /var/lock/subsys/ctdb ]; then
315 echo $"ctdb dead but subsys locked"
318 echo $"ctdb is stopped"
337 restart|reload|force-reload)
343 condrestart|try-restart)
344 ctdb status > /dev/null && restart || :
347 # used from cron to auto-restart ctdb
348 ctdb status > /dev/null || restart
351 echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"