# chkconfig: - 90 01
#
# description: Starts and stops the clustered tdb daemon
-# pidfile: /var/run/ctdbd/ctdbd.pid
+# pidfile: /var/run/ctdb/ctdbd.pid
#
### BEGIN INIT INFO
LC_ALL=en_US.UTF-8
}
+if [ -f /lib/lsb/init-functions ] ; then
+ . /lib/lsb/init-functions
+fi
+
# Avoid using root's TMPDIR
unset TMPDIR
export CTDB_INIT_STYLE
ctdbd=${CTDBD:-/usr/sbin/ctdbd}
+pidfile="/var/run/ctdb/ctdbd.pid"
if [ "$CTDB_VALGRIND" = "yes" ]; then
init_style="valgrind"
}
maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
+ mkdir -p $(dirname "$pidfile")
+ maybe_set "--pidfile" "$pidfile"
+
# build up CTDB_OPTIONS variable from optional parameters
maybe_set "--logfile" "$CTDB_LOGFILE"
maybe_set "--nlist" "$CTDB_NODES"
maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
maybe_set "--transport" "$CTDB_TRANSPORT"
maybe_set "-d" "$CTDB_DEBUGLEVEL"
- maybe_set "--debug-hung-script" "$CTDB_DEBUG_HUNG_SCRIPT"
maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
}
+export_debug_variables ()
+{
+ export CTDB_DEBUG_HUNG_SCRIPT CTDB_EXTERNAL_TRACE
+}
+
# Log given message or stdin to either syslog or a CTDB log file
do_log ()
{
- if [ "$CTDB_SYSLOG" = "yes" -o \
- "${CTDB_OPTIONS#*--syslog}" != "$CTDB_OPTIONS" ] ; then
-
- logger -t "ctdb.init" "$@"
- else
- _l="${CTDB_LOGFILE:-/var/log/log.ctdb}"
- {
- date
- if [ -n "$*" ] ; then
- echo "$*"
- else
- cat
- fi
- } >>"$_l"
- fi
+ script_log "ctdb.init" "$@"
}
select_tdb_checker ()
{
# Find the best TDB consistency check available.
use_tdb_tool_check=false
- if [ -x /usr/bin/tdbtool ] && \
- echo "help" | /usr/bin/tdbtool | grep -q check ; then
+ if which tdbtool >/dev/null 2>&1 && \
+ echo "help" | tdbtool | grep -q check ; then
use_tdb_tool_check=true
- elif [ -x /usr/bin/tdbtool -a -x /usr/bin/tdbdump ] ; then
+ elif which tdbtool >/dev/null 2>&1 && which tdbdump >/dev/null 2>&1 ; then
do_log <<EOF
WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
Using 'tdbdump' for database checks.
Consider updating 'tdbtool' for better checks!
EOF
- elif [ -x /usr/bin/tdbdump ] ; then
+ elif which tdbdump >/dev/null 2>&1 ; then
do_log <<EOF
WARNING: 'tdbtool' is not available.
Using 'tdbdump' to check the databases.
_timeout="${1:-10}" # default is 10 seconds
_count=0
- while ! ctdb ping >/dev/null 2>&1 ; do
+ while ! ctdb runstate startup running >/dev/null 2>&1 ; do
if [ $_count -ge $_timeout ] ; then
return 1
fi
done
}
-ctdbd=${CTDBD:-/usr/sbin/ctdbd}
-
-drop_all_public_ips() {
- while read _ip _iface _rest; do
- ip addr del $_ip dev $_iface >/dev/null 2>&1
- done <"${CTDB_PUBLIC_ADDRESSES:-/dev/null}"
-}
-
start() {
echo -n $"Starting ctdbd service: "
build_ctdb_options
+ export_debug_variables
+
# make sure we drop any ips that might still be held if previous
# instance of ctdb got killed with -9 or similar
- drop_all_public_ips
+ drop_all_public_ips "ctdb.init"
if select_tdb_checker ; then
check_persistent_databases || return $?
if [ $RETVAL -eq 0 ] ; then
if ! wait_until_ready ; then
RETVAL=1
+ echo "Timed out waiting for initialisation - killing CTDB"
pkill -9 -f $ctdbd >/dev/null 2>&1
fi
fi
# make sure all ips are dropped, pfkill -9 might leave them hanging around
drop_all_public_ips
+ rm -f "$pidfile"
+
case $init_style in
suse)
# re-set the return code to the recorded RETVAL in order
start
}
-status() {
- echo -n $"Checking for ctdbd service: "
- ctdb ping >/dev/null 2>&1 || {
- RETVAL=$?
- echo -n " ctdbd not running. "
- case $init_style in
- suse)
- set_retval $RETVAL
- rc_status -v
- ;;
- redhat)
- if [ -f /var/lock/subsys/ctdb ]; then
- echo $"ctdb dead but subsys locked"
- RETVAL=2
- else
- echo $"ctdb is stopped"
- RETVAL=3
- fi
- ;;
- esac
- return $RETVAL
- }
- echo ""
- ctdb status
+# Given that CTDB_VALGRIND is a debug option we don't support the pid
+# file. We just do a quick and dirty hack instead. Otherwise we just
+# end up re-implementing each distro's pidfile support...
+check_status_valgrind ()
+{
+ if pkill -0 -f "valgrind.*${ctdbd}" ; then
+ echo "ctdbd is running under valgrind..."
+ return 0
+ else
+ echo "ctdbd is not running"
+ return 1
+ fi
+}
+
+check_status ()
+{
+ # Backward compatibility. When we arrange to pass --pidfile to
+ # ctdbd we also create the directory that will contain it. If
+ # that directory is missing then we don't use the pidfile to check
+ # status.
+ if [ -d $(dirname "$pidfile") ] ; then
+ _pf_opt="-p $pidfile"
+ else
+ _pf_opt=""
+ fi
+
+ case "$init_style" in
+ valgrind)
+ check_status_valgrind
+ ;;
+ suse)
+ checkproc $_pf_opt "$ctdbd"
+ rc_status -v
+ ;;
+ redhat)
+ status $_pf_opt -l "ctdb" "$ctdbd"
+ ;;
+ debian)
+ status_of_proc $_pf_opt "$ctdbd" "ctdb"
+ ;;
+ esac
}
restart
;;
status)
- status
+ check_status
;;
condrestart|try-restart)
- ctdb status > /dev/null && restart || :
+ if check_status >/dev/null ; then
+ restart
+ fi
;;
cron)
# used from cron to auto-restart ctdb
- ctdb status > /dev/null || restart
+ check_status >/dev/null || restart
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"