3 ##############################
4 # ctdb: Starts the clustered tdb daemon
8 # description: Starts and stops the clustered tdb daemon
9 # pidfile: /var/run/ctdb/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 if [ -f /lib/lsb/init-functions ] ; then
36 . /lib/lsb/init-functions
39 # Avoid using root's TMPDIR
42 [ -z "$CTDB_BASE" ] && {
43 export CTDB_BASE="/etc/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}
57 pidfile="/var/run/ctdb/ctdbd.pid"
59 if [ "$CTDB_VALGRIND" = "yes" ]; then
62 init_style="$CTDB_INIT_STYLE"
65 build_ctdb_options () {
68 # If the 2nd arg is null then return - don't set anything.
69 # Else if the 3rd arg is set and it doesn't match the 2nd arg
71 [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
78 # For these options we're only passing a value-less flag.
84 CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
87 [ -z "$CTDB_RECOVERY_LOCK" ] && {
88 echo "No recovery lock specified. Starting CTDB without split brain prevention"
90 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
92 mkdir -p $(dirname "$pidfile")
93 maybe_set "--pidfile" "$pidfile"
95 # build up CTDB_OPTIONS variable from optional parameters
96 maybe_set "--logfile" "$CTDB_LOGFILE"
97 maybe_set "--nlist" "$CTDB_NODES"
98 maybe_set "--socket" "$CTDB_SOCKET"
99 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
100 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
101 maybe_set "--dbdir" "$CTDB_DBDIR"
102 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
103 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
104 maybe_set "--transport" "$CTDB_TRANSPORT"
105 maybe_set "-d" "$CTDB_DEBUGLEVEL"
106 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
107 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
108 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
109 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
110 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
111 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
112 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
113 maybe_set "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
114 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
115 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
118 export_debug_variables ()
120 export CTDB_DEBUG_HUNG_SCRIPT CTDB_EXTERNAL_TRACE
123 # Log given message or stdin to either syslog or a CTDB log file
126 script_log "ctdb.init" "$@"
129 select_tdb_checker ()
131 # Find the best TDB consistency check available.
132 use_tdb_tool_check=false
133 if which tdbtool >/dev/null 2>&1 && \
134 echo "help" | tdbtool | grep -q check ; then
136 use_tdb_tool_check=true
137 elif which tdbtool >/dev/null 2>&1 && which tdbdump >/dev/null 2>&1 ; then
139 WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
140 Using 'tdbdump' for database checks.
141 Consider updating 'tdbtool' for better checks!
143 elif which tdbdump >/dev/null 2>&1 ; then
145 WARNING: 'tdbtool' is not available.
146 Using 'tdbdump' to check the databases.
147 Consider installing a recent 'tdbtool' for better checks!
151 WARNING: Cannot check databases since neither
152 'tdbdump' nor 'tdbtool check' is available.
153 Consider installing tdbtool or at least tdbdump!
163 if $use_tdb_tool_check ; then
164 # tdbtool always exits with 0 :-(
165 if tdbtool "$_db" check 2>/dev/null |
166 grep -q "Database integrity is OK" ; then
172 tdbdump "$_db" >/dev/null 2>/dev/null
177 check_persistent_databases ()
179 _dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_DBDIR:-/var/ctdb}/persistent}"
180 mkdir -p "$_dir" 2>/dev/null
182 [ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
184 for _db in $(ls "$_dir/"*.tdb.*[0-9] 2>/dev/null) ; do
186 do_log "Persistent database $_db is corrupted! CTDB will not start."
192 check_non_persistent_databases ()
194 _dir="${CTDB_DBDIR:-/var/ctdb}"
195 mkdir -p "$_dir" 2>/dev/null
197 for _db in $(ls "${_dir}/"*.tdb.*[0-9] 2>/dev/null) ; do
199 _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
201 WARNING: database ${_db} is corrupted.
202 Moving to backup ${_backup} for later analysis.
206 # Now remove excess backups
207 ls -td "${_db}."*".corrupt" |
208 tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
219 wait_until_ready () {
220 _timeout="${1:-10}" # default is 10 seconds
223 while ! ctdb runstate startup running >/dev/null 2>&1 ; do
224 if [ $_count -ge $_timeout ] ; then
228 _count=$(($_count + 1))
233 echo -n $"Starting ctdbd service: "
235 ctdb ping >/dev/null 2>&1 && {
236 echo $"CTDB is already running"
240 # About to start new $ctdbd. The ping above has failed and any
241 # new $ctdbd will destroy the Unix domain socket, so any processes
242 # that aren't yet completely useless soon will be... so kill
248 export_debug_variables
250 # make sure we drop any ips that might still be held if previous
251 # instance of ctdb got killed with -9 or similar
252 drop_all_public_ips "ctdb.init"
254 if select_tdb_checker ; then
255 check_persistent_databases || return $?
256 check_non_persistent_databases
259 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
267 eval valgrind -q --log-file=/var/log/ctdb_valgrind \
268 $ctdbd --valgrinding "$CTDB_OPTIONS"
273 eval startproc $ctdbd "$CTDB_OPTIONS"
277 eval $ctdbd "$CTDB_OPTIONS"
279 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
282 eval start-stop-daemon --start --quiet --background \
283 --exec $ctdbd -- "$CTDB_OPTIONS"
288 if [ $RETVAL -eq 0 ] ; then
289 if ! wait_until_ready ; then
291 echo "Timed out waiting for initialisation - killing CTDB"
292 pkill -9 -f $ctdbd >/dev/null 2>&1
302 [ $RETVAL -eq 0 ] && success || failure
311 echo -n $"Shutting down ctdbd service: "
312 pkill -0 -f $ctdbd || {
313 echo -n " Warning: ctdbd not running ! "
324 ctdb shutdown >/dev/null 2>&1
327 while pkill -0 -f $ctdbd ; do
329 count=$(($count + 1))
330 [ $count -gt 30 ] && {
331 echo -n $"killing ctdbd "
333 pkill -9 -f $CTDB_BASE/events.d/
336 # make sure all ips are dropped, pfkill -9 might leave them hanging around
343 # re-set the return code to the recorded RETVAL in order
344 # to print the correct status message
349 [ $RETVAL -eq 0 ] && success || failure
350 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
363 # Given that CTDB_VALGRIND is a debug option we don't support the pid
364 # file. We just do a quick and dirty hack instead. Otherwise we just
365 # end up re-implementing each distro's pidfile support...
366 check_status_valgrind ()
368 if pkill -0 -f "valgrind.*${ctdbd}" ; then
369 echo "ctdbd is running under valgrind..."
372 echo "ctdbd is not running"
379 # Backward compatibility. When we arrange to pass --pidfile to
380 # ctdbd we also create the directory that will contain it. If
381 # that directory is missing then we don't use the pidfile to check
383 if [ -d $(dirname "$pidfile") ] ; then
384 _pf_opt="-p $pidfile"
389 case "$init_style" in
391 check_status_valgrind
394 checkproc $_pf_opt "$ctdbd"
398 status $_pf_opt -l "ctdb" "$ctdbd"
401 status_of_proc $_pf_opt "$ctdbd" "ctdb"
407 [ -x "$CTDB_BASE/rc.ctdb" ] && "$CTDB_BASE/rc.ctdb" $1
416 restart|reload|force-reload)
422 condrestart|try-restart)
423 if check_status >/dev/null ; then
428 # used from cron to auto-restart ctdb
429 check_status >/dev/null || restart
432 echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"