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 "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
106 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
107 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
113 test x"$TDBTOOL_HAS_CHECK" = x"1" && {
115 # Note tdbtool always exits with 0
117 local OK=`tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
118 test x"$OK" = x"1" || {
125 tdbdump $PDBASE >/dev/null 2>/dev/null || {
132 check_persistent_databases () {
133 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
134 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
135 local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
137 test -z "$ERRCOUNT" && {
140 test x"$ERRCOUNT" != x"0" && {
144 if test -x /usr/bin/tdbtool ; then
150 if test x"$HAVE_TDBTOOL" = x"1" ; then
151 TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
156 if test -x /usr/bin/tdbdump ; then
162 if test x"$HAVE_TDBDUMP" = x"0" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
163 echo "WARNING: Cannot check persistent databases since"
164 echo "neither 'tdbdump' nor 'tdbtool check' is available."
165 echo "Consider installing tdbtool or at least tdbdump!"
169 if test x"$HAVE_TDBDUMP" = x"1" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
170 if test x"$HAVE_TDBTOOL" = x"0"; then
171 echo "WARNING: 'tdbtool' is not available. Using 'tdbdump' to"
172 echo "check the persistent databases."
173 echo "Consider installing a recent 'tdbtool' for better checks!"
175 echo "WARNING: The installed 'tdbtool' does not offer the 'check'"
176 echo "subcommand. Using 'tdbdump' for persistent database checks."
177 echo "Consider updating 'tdbtool' for better checks!"
181 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
182 check_tdb $PDBASE || {
183 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
189 set_ctdb_variables () {
190 # set any tunables from the config file
191 set | grep ^CTDB_SET_ | cut -d_ -f3- |
193 varname=`echo $v | cut -d= -f1`
194 value=`echo $v | cut -d= -f2`
195 ctdb setvar $varname $value || RETVAL=1
203 wait_until_ready () {
204 _timeout="${1:-10}" # default is 10 seconds
207 while ! ctdb ping >/dev/null 2>&1 ; do
208 if [ $_count -ge $_timeout ] ; then
212 _count=$(($_count + 1))
216 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
218 drop_all_public_ips() {
219 [ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
223 cat $CTDB_PUBLIC_ADDRESSES | while read IP IFACE REST; do
224 ip addr del $IP dev $IFACE >/dev/null 2>/dev/null
229 echo -n $"Starting ctdbd service: "
231 ctdb ping >/dev/null 2>&1 && {
232 echo $"CTDB is already running"
238 # make sure we drop any ips that might still be held if previous
239 # instance of ctdb got killed with -9 or similar
242 check_persistent_databases || return $?
244 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
252 eval valgrind -q --log-file=/var/log/ctdb_valgrind \
253 $ctdbd --valgrinding "$CTDB_OPTIONS"
258 eval startproc $ctdbd "$CTDB_OPTIONS"
262 eval $ctdbd "$CTDB_OPTIONS"
264 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
267 eval start-stop-daemon --start --quiet --background \
268 --exec $ctdbd -- "$CTDB_OPTIONS"
273 if [ $RETVAL -eq 0 ] ; then
274 if wait_until_ready ; then
278 pkill -9 -f $ctdbd >/dev/null 2>&1
288 [ $RETVAL -eq 0 ] && success || failure
297 echo -n $"Shutting down ctdbd service: "
298 pkill -0 -f $ctdbd || {
299 echo -n " Warning: ctdbd not running ! "
310 ctdb shutdown >/dev/null 2>&1
313 while pkill -0 -f $ctdbd ; do
315 count=$(($count + 1))
316 [ $count -gt 10 ] && {
317 echo -n $"killing ctdbd "
319 pkill -9 -f $CTDB_BASE/events.d/
322 # make sure all ips are dropped, pfkill -9 might leave them hanging around
327 # re-set the return code to the recorded RETVAL in order
328 # to print the correct status message
333 [ $RETVAL -eq 0 ] && success || failure
334 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
348 echo -n $"Checking for ctdbd service: "
349 ctdb ping >/dev/null 2>&1 || {
351 echo -n " ctdbd not running. "
358 if [ -f /var/lock/subsys/ctdb ]; then
359 echo $"ctdb dead but subsys locked"
362 echo $"ctdb is stopped"
381 restart|reload|force-reload)
387 condrestart|try-restart)
388 ctdb status > /dev/null && restart || :
391 # used from cron to auto-restart ctdb
392 ctdb status > /dev/null || restart
395 echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"