2007-05-28 00:48:18 +04:00
#!/bin/sh
#
2007-06-01 17:25:33 +04:00
##############################
2008-08-25 04:13:18 +04:00
# ctdb: Starts the clustered tdb daemon
#
2009-04-23 05:35:42 +04:00
# chkconfig: - 90 01
2008-08-25 04:13:18 +04:00
#
# description: Starts and stops the clustered tdb daemon
# pidfile: /var/run/ctdbd/ctdbd.pid
#
2007-06-01 17:25:33 +04:00
### BEGIN INIT INFO
2008-08-25 04:13:18 +04:00
# Provides: ctdb
# Required-Start: $network
2008-12-19 13:50:06 +03:00
# Required-Stop: $network
2007-06-01 17:25:33 +04:00
# Default-Stop:
2008-07-05 16:28:27 +04:00
# Default-Start: 3 5
2008-08-25 04:13:18 +04:00
# Short-Description: start and stop ctdb service
# Description: initscript for the ctdb service
2007-06-01 17:25:33 +04:00
### END INIT INFO
2007-05-28 00:48:18 +04:00
# Source function library.
if [ -f /etc/init.d/functions ] ; then
2009-07-07 07:45:19 +04:00
. /etc/init.d/functions
2007-05-28 00:48:18 +04:00
elif [ -f /etc/rc.d/init.d/functions ] ; then
2009-07-07 07:45:19 +04:00
. /etc/rc.d/init.d/functions
2007-05-28 00:48:18 +04:00
fi
2007-06-03 11:53:26 +04:00
[ -f /etc/rc.status ] && {
. /etc/rc.status
rc_reset
LC_ALL=en_US.UTF-8
}
2007-05-28 00:48:18 +04:00
# Avoid using root's TMPDIR
unset TMPDIR
2007-09-14 08:14:03 +04:00
[ -z "$CTDB_BASE" ] && {
export CTDB_BASE="/etc/ctdb"
}
. $CTDB_BASE/functions
2007-06-03 16:07:07 +04:00
loadconfig network
loadconfig ctdb
2009-07-07 07:45:19 +04:00
# check networking is up (for redhat)
[ "$NETWORKING" = "no" ] && exit 0
2007-05-28 00:48:18 +04:00
2009-01-16 15:28:19 +03:00
detect_init_style
export CTDB_INIT_STYLE
2009-07-07 07:45:19 +04:00
ctdbd=${CTDBD:-/usr/sbin/ctdbd}
if [ "$CTDB_VALGRIND" = "yes" ]; then
init_style="valgrind"
2009-01-16 15:28:19 +03:00
else
2009-07-07 07:45:19 +04:00
init_style="$CTDB_INIT_STYLE"
2008-07-04 10:58:14 +04:00
fi
2007-06-01 17:25:33 +04:00
2009-07-07 07:45:19 +04: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
val="$2"
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 05:12:04 +04:00
[ -z "$CTDB_RECOVERY_LOCK" ] && {
echo "No recovery lock specified. Starting CTDB without split brain prevention"
}
2009-07-07 07:45:19 +04: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 05:57:20 +04:00
maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
2009-07-07 07:45:19 +04: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"
2009-09-15 13:33:35 +04:00
maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
2009-07-07 07:45:19 +04:00
}
check_persistent_databases () {
PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
/usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
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 16:01:37 +03:00
set_retval() {
2009-07-07 07:45:19 +04:00
return $1
2008-12-12 18:04:29 +03:00
}
2009-06-02 04:01:50 +04:00
ctdbd=${CTDBD:-/usr/sbin/ctdbd}
2007-05-28 00:48:18 +04:00
start() {
2009-07-07 07:45:19 +04:00
echo -n $"Starting ctdbd service: "
ctdb ping >/dev/null 2>&1 && {
echo $"CTDB is already running"
return 1
}
build_ctdb_options
check_persistent_databases || return $?
2009-11-05 07:57:46 +03:00
if [ yes == "$CTDB_SUPPRESS_COREFILE" ]; then
ulimit -c 0
else
ulimit -c unlimited
fi
2009-07-07 07:45:19 +04:00
case $init_style in
valgrind)
valgrind -q --log-file=/var/log/ctdb_valgrind \
$ctdbd --nosetsched $CTDB_OPTIONS
RETVAL=$?
echo
;;
suse)
startproc $ctdbd $CTDB_OPTIONS
rc_status -v
RETVAL=$?
;;
redhat)
daemon $ctdbd $CTDB_OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
;;
2009-09-15 13:33:35 +04:00
debian)
2009-07-07 07:45:19 +04:00
start-stop-daemon --start --quiet --background \
--exec $ctdbd -- $CTDB_OPTIONS
RETVAL=$?
;;
esac
sleep 1
set_ctdb_variables
return $RETVAL
}
2008-05-12 10:44:33 +04:00
2009-07-07 07:45:19 +04:00
stop() {
echo -n $"Shutting down ctdbd service: "
pkill -0 -f $ctdbd || {
echo -n " Warning: ctdbd not running ! "
2007-06-01 17:25:33 +04:00
case $init_style in
suse)
rc_status -v
;;
redhat)
2009-07-07 07:45:19 +04:00
echo ""
2007-06-03 13:24:52 +04:00
;;
2007-06-01 17:25:33 +04:00
esac
2009-07-07 07:45:19 +04:00
return 0
}
ctdb shutdown >/dev/null 2>&1
RETVAL=$?
count=0
while pkill -0 -f $ctdbd ; do
2008-01-04 04:41:53 +03:00
sleep 1
2009-07-07 07:45:19 +04: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 09:35:56 +04:00
[ $RETVAL -eq 0 ] && success || failure
2009-07-07 07:45:19 +04:00
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
echo ""
;;
esac
return $RETVAL
}
2008-01-04 04:41:53 +03:00
2009-07-07 07:45:19 +04:00
restart() {
stop
start
2007-05-28 00:48:18 +04:00
}
2009-07-07 07:45:19 +04:00
status() {
echo -n $"Checking for ctdbd service: "
ctdb ping >/dev/null 2>&1 || {
2007-05-28 00:48:18 +04:00
RETVAL=$?
2009-07-07 07:45:19 +04:00
echo -n " ctdbd not running. "
2007-06-01 17:25:33 +04:00
case $init_style in
suse)
2008-12-12 18:04:29 +03:00
set_retval $RETVAL
2007-06-01 17:25:33 +04:00
rc_status -v
;;
redhat)
echo ""
;;
esac
2008-12-12 18:05:04 +03:00
return $RETVAL
2009-07-07 07:45:19 +04:00
}
echo ""
ctdb status
}
2007-05-28 00:48:18 +04:00
2009-11-19 08:48:19 +03:00
case "$cmd" in
2009-07-07 07:45:19 +04:00
start)
2007-05-28 00:48:18 +04:00
start
;;
2009-07-07 07:45:19 +04:00
stop)
2007-05-28 00:48:18 +04:00
stop
;;
2009-07-07 07:45:19 +04:00
restart|reload)
2007-05-28 00:48:18 +04:00
restart
;;
2009-07-07 07:45:19 +04:00
status)
2007-06-02 12:51:05 +04:00
status
2007-05-28 00:48:18 +04:00
;;
2009-07-07 07:45:19 +04:00
condrestart)
2007-06-01 17:25:33 +04:00
ctdb status > /dev/null && restart || :
2007-05-28 00:48:18 +04:00
;;
2009-07-07 07:45:19 +04:00
cron)
2007-06-02 12:51:05 +04:00
# used from cron to auto-restart ctdb
2007-06-03 04:29:57 +04:00
ctdb status > /dev/null || restart
2007-06-02 12:51:05 +04:00
;;
2009-07-07 07:45:19 +04:00
*)
2007-06-02 12:51:05 +04:00
echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
2007-05-28 00:48:18 +04:00
exit 1
esac
exit $?