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 . $CTDB_BASE/functions
46 # check networking is up (for redhat)
47 [ "$NETWORKING" = "no" ] && exit 0
50 export CTDB_INIT_STYLE
52 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
54 if [ "$CTDB_VALGRIND" = "yes" ]; then
57 init_style="$CTDB_INIT_STYLE"
60 build_ctdb_options () {
63 # If the 2nd arg is null then return - don't set anything.
64 # Else if the 3rd arg is set and it doesn't match the 2nd arg
66 [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
73 # For these options we're only passing a value-less flag.
79 CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
82 [ -z "$CTDB_RECOVERY_LOCK" ] && {
83 echo "No recovery lock specified. Starting CTDB without split brain prevention"
85 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
87 # build up CTDB_OPTIONS variable from optional parameters
88 maybe_set "--logfile" "$CTDB_LOGFILE"
89 maybe_set "--nlist" "$CTDB_NODES"
90 maybe_set "--socket" "$CTDB_SOCKET"
91 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
92 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
93 maybe_set "--dbdir" "$CTDB_DBDIR"
94 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
95 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
96 maybe_set "--transport" "$CTDB_TRANSPORT"
97 maybe_set "-d" "$CTDB_DEBUGLEVEL"
98 maybe_set "--debug-hung-script" "$CTDB_DEBUG_HUNG_SCRIPT"
99 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
100 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
101 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
102 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
103 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
104 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
105 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
106 maybe_set "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
107 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
108 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
111 # Log given message or stdin to either syslog or a CTDB log file
114 if [ "$CTDB_SYSLOG" = "yes" -o \
115 "${CTDB_OPTIONS#*--syslog}" != "$CTDB_OPTIONS" ] ; then
117 logger -t "ctdb.init" "$@"
119 _l="${CTDB_LOGFILE:-/var/log/log.ctdb}"
122 if [ -n "$*" ] ; then
131 select_tdb_checker ()
133 # Find the best TDB consistency check available.
134 use_tdb_tool_check=false
135 if [ -x /usr/bin/tdbtool ] && \
136 echo "help" | /usr/bin/tdbtool | grep -q check ; then
138 use_tdb_tool_check=true
139 elif [ -x /usr/bin/tdbtool -a -x /usr/bin/tdbdump ] ; then
141 WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
142 Using 'tdbdump' for database checks.
143 Consider updating 'tdbtool' for better checks!
145 elif [ -x /usr/bin/tdbdump ] ; then
147 WARNING: 'tdbtool' is not available.
148 Using 'tdbdump' to check the databases.
149 Consider installing a recent 'tdbtool' for better checks!
153 WARNING: Cannot check databases since neither
154 'tdbdump' nor 'tdbtool check' is available.
155 Consider installing tdbtool or at least tdbdump!
165 if $use_tdb_tool_check ; then
166 # tdbtool always exits with 0 :-(
167 if tdbtool "$_db" check 2>/dev/null |
168 grep -q "Database integrity is OK" ; then
174 tdbdump "$_db" >/dev/null 2>/dev/null
179 check_persistent_databases ()
181 _dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_DBDIR:-/var/ctdb}/persistent}"
182 mkdir -p "$_dir" 2>/dev/null
184 [ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
186 for _db in $(ls "$_dir/"*.tdb.*[0-9] 2>/dev/null) ; do
188 do_log "Persistent database $_db is corrupted! CTDB will not start."
194 check_non_persistent_databases ()
196 _dir="${CTDB_DBDIR:-/var/ctdb}"
197 mkdir -p "$_dir" 2>/dev/null
199 for _db in $(ls "${_dir}/"*.tdb.*[0-9] 2>/dev/null) ; do
201 _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
203 WARNING: database ${_db} is corrupted.
204 Moving to backup ${_backup} for later analysis.
208 # Now remove excess backups
209 ls -td "${_db}."*".corrupt" |
210 tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
217 set_ctdb_variables () {
218 # set any tunables from the config file
219 set | grep ^CTDB_SET_ | cut -d_ -f3- |
221 varname=`echo $v | cut -d= -f1`
222 value=`echo $v | cut -d= -f2`
223 ctdb setvar $varname $value || RETVAL=1
231 wait_until_ready () {
232 _timeout="${1:-10}" # default is 10 seconds
235 while ! ctdb ping >/dev/null 2>&1 ; do
236 if [ $_count -ge $_timeout ] ; then
240 _count=$(($_count + 1))
244 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
246 drop_all_public_ips() {
247 [ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
251 cat $CTDB_PUBLIC_ADDRESSES | while read IP IFACE REST; do
252 ip addr del $IP dev $IFACE >/dev/null 2>/dev/null
257 echo -n $"Starting ctdbd service: "
259 ctdb ping >/dev/null 2>&1 && {
260 echo $"CTDB is already running"
266 # make sure we drop any ips that might still be held if previous
267 # instance of ctdb got killed with -9 or similar
270 if select_tdb_checker ; then
271 check_persistent_databases || return $?
272 check_non_persistent_databases
275 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
283 eval valgrind -q --log-file=/var/log/ctdb_valgrind \
284 $ctdbd --valgrinding "$CTDB_OPTIONS"
289 eval startproc $ctdbd "$CTDB_OPTIONS"
293 eval $ctdbd "$CTDB_OPTIONS"
295 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
298 eval start-stop-daemon --start --quiet --background \
299 --exec $ctdbd -- "$CTDB_OPTIONS"
304 if [ $RETVAL -eq 0 ] ; then
305 if wait_until_ready ; then
309 pkill -9 -f $ctdbd >/dev/null 2>&1
319 [ $RETVAL -eq 0 ] && success || failure
328 echo -n $"Shutting down ctdbd service: "
329 pkill -0 -f $ctdbd || {
330 echo -n " Warning: ctdbd not running ! "
341 ctdb shutdown >/dev/null 2>&1
344 while pkill -0 -f $ctdbd ; do
346 count=$(($count + 1))
347 [ $count -gt 30 ] && {
348 echo -n $"killing ctdbd "
350 pkill -9 -f $CTDB_BASE/events.d/
353 # make sure all ips are dropped, pfkill -9 might leave them hanging around
358 # re-set the return code to the recorded RETVAL in order
359 # to print the correct status message
364 [ $RETVAL -eq 0 ] && success || failure
365 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
379 echo -n $"Checking for ctdbd service: "
380 ctdb ping >/dev/null 2>&1 || {
382 echo -n " ctdbd not running. "
389 if [ -f /var/lock/subsys/ctdb ]; then
390 echo $"ctdb dead but subsys locked"
393 echo $"ctdb is stopped"
405 [ -f "$CTDB_BASE/rc.ctdb" ] && "$CTDB_BASE/rc.ctdb" $1
414 restart|reload|force-reload)
420 condrestart|try-restart)
421 ctdb status > /dev/null && restart || :
424 # used from cron to auto-restart ctdb
425 ctdb status > /dev/null || restart
428 echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"