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 "--notification-script" "$CTDB_NOTIFY_SCRIPT"
99 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
100 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
101 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
102 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
103 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
104 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
105 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
106 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
112 local TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
114 test x"$TDBTOOL_HAS_CHECK" = x"1" && {
116 # Note tdbtool always exits with 0
118 local OK=`/usr/bin/tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
119 test x"$OK" = x"1" || {
126 /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
133 check_persistent_databases () {
134 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
135 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
136 local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
138 test -z "$ERRCOUNT" && {
141 test x"$ERRCOUNT" != x"0" && {
144 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
145 check_tdb $PDBASE || {
146 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
152 set_ctdb_variables () {
153 # set any tunables from the config file
154 set | grep ^CTDB_SET_ | cut -d_ -f3- |
156 varname=`echo $v | cut -d= -f1`
157 value=`echo $v | cut -d= -f2`
158 ctdb setvar $varname $value || RETVAL=1
166 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
169 echo -n $"Starting ctdbd service: "
171 ctdb ping >/dev/null 2>&1 && {
172 echo $"CTDB is already running"
178 check_persistent_databases || return $?
180 if [ yes == "$CTDB_SUPPRESS_COREFILE" ]; then
188 valgrind -q --log-file=/var/log/ctdb_valgrind \
189 $ctdbd --valgrinding $CTDB_OPTIONS
194 startproc $ctdbd $CTDB_OPTIONS
199 daemon $ctdbd $CTDB_OPTIONS
202 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
205 start-stop-daemon --start --quiet --background \
206 --exec $ctdbd -- $CTDB_OPTIONS
219 echo -n $"Shutting down ctdbd service: "
220 pkill -0 -f $ctdbd || {
221 echo -n " Warning: ctdbd not running ! "
232 ctdb shutdown >/dev/null 2>&1
235 while pkill -0 -f $ctdbd ; do
237 count=$(($count + 1))
238 [ $count -gt 10 ] && {
239 echo -n $"killing ctdbd "
241 pkill -9 -f $CTDB_BASE/events.d/
246 # re-set the return code to the recorded RETVAL in order
247 # to print the correct status message
252 [ $RETVAL -eq 0 ] && success || failure
253 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
266 echo -n $"Checking for ctdbd service: "
267 ctdb ping >/dev/null 2>&1 || {
269 echo -n " ctdbd not running. "
300 ctdb status > /dev/null && restart || :
303 # used from cron to auto-restart ctdb
304 ctdb status > /dev/null || restart
307 echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"