2007-05-27 16:48:18 -04:00
#!/bin/sh
#
2007-06-01 23:25:33 +10:00
##############################
2008-08-25 10:13:18 +10:00
# ctdb: Starts the clustered tdb daemon
#
2009-04-23 11:35:42 +10:00
# chkconfig: - 90 01
2008-08-25 10:13:18 +10:00
#
# description: Starts and stops the clustered tdb daemon
# pidfile: /var/run/ctdbd/ctdbd.pid
#
2007-06-01 23:25:33 +10:00
### BEGIN INIT INFO
2008-08-25 10:13:18 +10:00
# Provides: ctdb
# Required-Start: $network
2008-12-19 11:50:06 +01:00
# Required-Stop: $network
2007-06-01 23:25:33 +10:00
# Default-Stop:
2008-07-05 14:28:27 +02:00
# Default-Start: 3 5
2008-08-25 10:13:18 +10:00
# Short-Description: start and stop ctdb service
# Description: initscript for the ctdb service
2007-06-01 23:25:33 +10:00
### END INIT INFO
2007-05-27 16:48:18 -04:00
# Source function library.
if [ -f /etc/init.d/functions ] ; then
2009-07-07 13:45:19 +10:00
. /etc/init.d/functions
2007-05-27 16:48:18 -04:00
elif [ -f /etc/rc.d/init.d/functions ] ; then
2009-07-07 13:45:19 +10:00
. /etc/rc.d/init.d/functions
2007-05-27 16:48:18 -04:00
fi
2007-06-03 17:53:26 +10:00
[ -f /etc/rc.status ] && {
. /etc/rc.status
rc_reset
LC_ALL=en_US.UTF-8
}
2007-05-27 16:48:18 -04:00
# Avoid using root's TMPDIR
unset TMPDIR
2007-09-14 14:14:03 +10:00
[ -z "$CTDB_BASE" ] && {
export CTDB_BASE="/etc/ctdb"
}
. $CTDB_BASE/functions
2007-06-03 22:07:07 +10:00
loadconfig network
loadconfig ctdb
2009-07-07 13:45:19 +10:00
# check networking is up (for redhat)
[ "$NETWORKING" = "no" ] && exit 0
2007-05-27 16:48:18 -04:00
2009-01-16 13:28:19 +01:00
detect_init_style
export CTDB_INIT_STYLE
2009-07-07 13:45:19 +10:00
ctdbd=${CTDBD:-/usr/sbin/ctdbd}
if [ "$CTDB_VALGRIND" = "yes" ]; then
init_style="valgrind"
2009-01-16 13:28:19 +01:00
else
2009-07-07 13:45:19 +10:00
init_style="$CTDB_INIT_STYLE"
2008-07-04 16:58:14 +10:00
fi
2007-06-01 23:25:33 +10:00
2009-07-07 13:45:19 +10:00
build_ctdb_options () {
maybe_set () {
# If the 2nd arg is null then return - don't set anything.
# Else if the 3rd arg is set and it doesn't match the 2nd arg
# then return
[ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
2010-01-22 13:19:00 +11:00
val="'$2'"
2009-07-07 13:45:19 +10:00
case "$1" in
--*) sep="=" ;;
-*) sep=" " ;;
esac
# For these options we're only passing a value-less flag.
[ -n "$3" ] && {
val=""
sep=""
}
CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
}
2009-10-14 12:12:04 +11:00
[ -z "$CTDB_RECOVERY_LOCK" ] && {
echo "No recovery lock specified. Starting CTDB without split brain prevention"
}
2009-07-07 13:45:19 +10:00
maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
# build up CTDB_OPTIONS variable from optional parameters
maybe_set "--logfile" "$CTDB_LOGFILE"
maybe_set "--nlist" "$CTDB_NODES"
maybe_set "--socket" "$CTDB_SOCKET"
maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
maybe_set "--dbdir" "$CTDB_DBDIR"
maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
maybe_set "--transport" "$CTDB_TRANSPORT"
maybe_set "-d" "$CTDB_DEBUGLEVEL"
maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
2009-07-09 11:57:20 +10:00
maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
2009-07-07 13:45:19 +10:00
maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
2010-01-15 15:38:56 +11:00
maybe_set "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
2009-09-15 19:33:35 +10:00
maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
2009-12-07 10:53:31 +01:00
maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
2009-07-07 13:45:19 +10:00
}
2009-12-07 10:46:10 +01:00
check_tdb () {
local PDBASE=$1
test x"$TDBTOOL_HAS_CHECK" = x"1" && {
#
# Note tdbtool always exits with 0
#
2011-04-13 12:08:09 +10:00
local OK=`tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
2009-12-07 10:46:10 +01:00
test x"$OK" = x"1" || {
return 1;
}
return 0;
}
2011-04-13 12:08:09 +10:00
tdbdump $PDBASE >/dev/null 2>/dev/null || {
2009-12-07 10:46:10 +01:00
return $?;
}
return 0;
}
2009-07-07 13:45:19 +10:00
check_persistent_databases () {
PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
2009-12-07 10:53:31 +01:00
local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
test -z "$ERRCOUNT" && {
ERRCOUNT="0"
}
test x"$ERRCOUNT" != x"0" && {
return 0;
}
2011-04-05 13:43:56 +02:00
if test -x /usr/bin/tdbtool ; then
HAVE_TDBTOOL=1
else
HAVE_TDBTOOL=0
fi
if test x"$HAVE_TDBTOOL" = x"1" ; then
TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
else
TDBTOOL_HAS_CHECK=0
fi
if test -x /usr/bin/tdbdump ; then
HAVE_TDBDUMP=1
else
HAVE_TDBDUMP=0
fi
if test x"$HAVE_TDBDUMP" = x"0" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
echo "WARNING: Cannot check persistent databases since"
echo "neither 'tdbdump' nor 'tdbtool check' is available."
echo "Consider installing tdbtool or at least tdbdump!"
return 0
fi
2011-04-05 13:50:00 +02:00
if test x"$HAVE_TDBDUMP" = x"1" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
if test x"$HAVE_TDBTOOL" = x"0"; then
echo "WARNING: 'tdbtool' is not available. Using 'tdbdump' to"
echo "check the persistent databases."
echo "Consider installing a recent 'tdbtool' for better checks!"
else
echo "WARNING: The installed 'tdbtool' does not offer the 'check'"
echo "subcommand. Using 'tdbdump' for persistent database checks."
echo "Consider updating 'tdbtool' for better checks!"
fi
fi
2009-07-07 13:45:19 +10:00
for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
2009-12-07 10:46:10 +01:00
check_tdb $PDBASE || {
2009-07-07 13:45:19 +10:00
echo "Persistent database $PDBASE is corrupted! CTDB will not start."
return 1
}
done
}
set_ctdb_variables () {
# set any tunables from the config file
set | grep ^CTDB_SET_ | cut -d_ -f3- |
while read v; do
varname=`echo $v | cut -d= -f1`
value=`echo $v | cut -d= -f2`
ctdb setvar $varname $value || RETVAL=1
done || exit 1
}
2009-01-16 14:01:37 +01:00
set_retval() {
2009-07-07 13:45:19 +10:00
return $1
2008-12-12 16:04:29 +01:00
}
2010-08-05 15:29:40 +10:00
wait_until_ready () {
_timeout="${1:-10}" # default is 10 seconds
_count=0
while ! ctdb ping >/dev/null 2>&1 ; do
if [ $_count -ge $_timeout ] ; then
return 1
fi
sleep 1
_count=$(($_count + 1))
done
}
2009-06-02 10:01:50 +10:00
ctdbd=${CTDBD:-/usr/sbin/ctdbd}
2007-05-27 16:48:18 -04:00
start() {
2009-07-07 13:45:19 +10:00
echo -n $"Starting ctdbd service: "
ctdb ping >/dev/null 2>&1 && {
echo $"CTDB is already running"
2010-02-22 14:06:52 +11:00
return 0
2009-07-07 13:45:19 +10:00
}
build_ctdb_options
check_persistent_databases || return $?
2010-01-22 17:13:17 +11:00
if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
2009-11-05 15:57:46 +11:00
ulimit -c 0
else
ulimit -c unlimited
fi
2009-07-07 13:45:19 +10:00
case $init_style in
valgrind)
2010-01-22 13:19:00 +11:00
eval valgrind -q --log-file=/var/log/ctdb_valgrind \
$ctdbd --valgrinding "$CTDB_OPTIONS"
2009-07-07 13:45:19 +10:00
RETVAL=$?
echo
;;
suse)
2010-01-22 13:19:00 +11:00
eval startproc $ctdbd "$CTDB_OPTIONS"
2009-07-07 13:45:19 +10:00
RETVAL=$?
;;
redhat)
2010-01-22 13:19:00 +11:00
eval $ctdbd "$CTDB_OPTIONS"
2009-07-07 13:45:19 +10:00
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
;;
2009-09-15 19:33:35 +10:00
debian)
2010-01-22 13:19:00 +11:00
eval start-stop-daemon --start --quiet --background \
--exec $ctdbd -- "$CTDB_OPTIONS"
2009-07-07 13:45:19 +10:00
RETVAL=$?
;;
esac
2010-08-05 15:29:40 +10:00
if [ $RETVAL -eq 0 ] ; then
if wait_until_ready ; then
set_ctdb_variables
else
RETVAL=1
pkill -9 -f $ctdbd >/dev/null 2>&1
fi
fi
2009-07-07 13:45:19 +10:00
2010-08-05 15:29:40 +10:00
case $init_style in
suse)
set_retval $RETVAL
rc_status -v
;;
redhat)
[ $RETVAL -eq 0 ] && success || failure
echo
;;
esac
2009-07-07 13:45:19 +10:00
return $RETVAL
2010-02-22 14:06:52 +11:00
}
2008-05-12 16:44:33 +10:00
2009-07-07 13:45:19 +10:00
stop() {
echo -n $"Shutting down ctdbd service: "
pkill -0 -f $ctdbd || {
echo -n " Warning: ctdbd not running ! "
2007-06-01 23:25:33 +10:00
case $init_style in
suse)
rc_status -v
;;
redhat)
2009-07-07 13:45:19 +10:00
echo ""
2007-06-03 19:24:52 +10:00
;;
2007-06-01 23:25:33 +10:00
esac
2009-07-07 13:45:19 +10:00
return 0
}
ctdb shutdown >/dev/null 2>&1
RETVAL=$?
count=0
while pkill -0 -f $ctdbd ; do
2008-01-04 12:41:53 +11:00
sleep 1
2009-07-07 13:45:19 +10:00
count=$(($count + 1))
[ $count -gt 10 ] && {
echo -n $"killing ctdbd "
pkill -9 -f $ctdbd
pkill -9 -f $CTDB_BASE/events.d/
}
done
case $init_style in
suse)
# re-set the return code to the recorded RETVAL in order
# to print the correct status message
set_retval $RETVAL
rc_status -v
;;
redhat)
2009-10-16 16:35:56 +11:00
[ $RETVAL -eq 0 ] && success || failure
2009-07-07 13:45:19 +10:00
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
echo ""
;;
esac
return $RETVAL
}
2008-01-04 12:41:53 +11:00
2009-07-07 13:45:19 +10:00
restart() {
stop
start
2010-02-22 14:06:52 +11:00
}
2007-05-27 16:48:18 -04:00
2009-07-07 13:45:19 +10:00
status() {
echo -n $"Checking for ctdbd service: "
ctdb ping >/dev/null 2>&1 || {
2007-05-27 16:48:18 -04:00
RETVAL=$?
2009-07-07 13:45:19 +10:00
echo -n " ctdbd not running. "
2007-06-01 23:25:33 +10:00
case $init_style in
suse)
2008-12-12 16:04:29 +01:00
set_retval $RETVAL
2007-06-01 23:25:33 +10:00
rc_status -v
;;
redhat)
2010-02-22 14:06:52 +11:00
if [ -f /var/lock/subsys/ctdb ]; then
echo $"ctdb dead but subsys locked"
RETVAL=2
else
echo $"ctdb is stopped"
RETVAL=3
fi
2007-06-01 23:25:33 +10:00
;;
esac
2008-12-12 16:05:04 +01:00
return $RETVAL
2009-07-07 13:45:19 +10:00
}
echo ""
ctdb status
}
2007-05-27 16:48:18 -04:00
2009-12-01 17:43:47 +11:00
case "$1" in
2009-07-07 13:45:19 +10:00
start)
2007-05-27 16:48:18 -04:00
start
;;
2009-07-07 13:45:19 +10:00
stop)
2007-05-27 16:48:18 -04:00
stop
;;
2010-02-22 14:06:52 +11:00
restart|reload|force-reload)
2007-05-27 16:48:18 -04:00
restart
;;
2009-07-07 13:45:19 +10:00
status)
2007-06-02 18:51:05 +10:00
status
2007-05-27 16:48:18 -04:00
;;
2010-02-22 14:06:52 +11:00
condrestart|try-restart)
2007-06-01 23:25:33 +10:00
ctdb status > /dev/null && restart || :
2007-05-27 16:48:18 -04:00
;;
2009-07-07 13:45:19 +10:00
cron)
2007-06-02 18:51:05 +10:00
# used from cron to auto-restart ctdb
2007-06-03 10:29:57 +10:00
ctdb status > /dev/null || restart
2007-06-02 18:51:05 +10:00
;;
2009-07-07 13:45:19 +10:00
*)
2010-02-22 14:06:52 +11:00
echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
2007-05-27 16:48:18 -04:00
exit 1
esac
exit $?