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
#
# chkconfig: - 90 36
#
# 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
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
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
2007-06-01 17:25:33 +04:00
# check networking is up (for redhat)
2007-06-03 16:11:48 +04:00
[ "${NETWORKING}" = "no" ] && exit 0
2007-05-28 00:48:18 +04:00
2007-06-02 05:36:42 +04:00
[ -z "$CTDB_RECOVERY_LOCK" ] && {
echo "You must configure the location of the CTDB_RECOVERY_LOCK"
exit 1
}
CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
# build up CTDB_OPTIONS variable from optional parameters
2007-06-04 09:44:52 +04:00
[ -z "$CTDB_LOGFILE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --logfile=$CTDB_LOGFILE"
[ -z "$CTDB_NODES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --nlist=$CTDB_NODES"
[ -z "$CTDB_SOCKET" ] || CTDB_OPTIONS="$CTDB_OPTIONS --socket=$CTDB_SOCKET"
[ -z "$CTDB_PUBLIC_ADDRESSES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=$CTDB_PUBLIC_ADDRESSES"
2007-09-10 09:09:28 +04:00
[ -z "$CTDB_PUBLIC_INTERFACE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=$CTDB_PUBLIC_INTERFACE"
2007-10-10 03:42:32 +04:00
[ -z "$CTDB_SINGLE_PUBLIC_IP" ] || CTDB_OPTIONS="$CTDB_OPTIONS --single-public-ip=$CTDB_SINGLE_PUBLIC_IP"
2007-06-04 09:44:52 +04:00
[ -z "$CTDB_DBDIR" ] || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir=$CTDB_DBDIR"
2007-09-21 10:12:04 +04:00
[ -z "$CTDB_DBDIR_PERSISTENT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir-persistent=$CTDB_DBDIR_PERSISTENT"
2007-08-15 09:01:31 +04:00
[ -z "$CTDB_EVENT_SCRIPT_DIR" ] || CTDB_OPTIONS="$CTDB_OPTIONS --event-script-dir $CTDB_EVENT_SCRIPT_DIR"
2007-06-04 09:44:52 +04:00
[ -z "$CTDB_TRANSPORT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --transport $CTDB_TRANSPORT"
[ -z "$CTDB_DEBUGLEVEL" ] || CTDB_OPTIONS="$CTDB_OPTIONS -d $CTDB_DEBUGLEVEL"
2008-02-22 01:42:52 +03:00
[ -z "$CTDB_START_AS_DISABLED" ] || [ "$CTDB_START_AS_DISABLED" != "yes" ] || {
CTDB_OPTIONS="$CTDB_OPTIONS --start-as-disabled"
}
2008-05-06 07:56:56 +04:00
[ -z "$CTDB_CAPABILITY_RECMASTER" ] || [ "$CTDB_CAPABILITY_RECMASTER" != "no" ] || {
2008-05-06 04:41:22 +04:00
CTDB_OPTIONS="$CTDB_OPTIONS --no-recmaster"
}
2008-05-06 07:56:56 +04:00
[ -z "$CTDB_CAPABILITY_LMASTER" ] || [ "$CTDB_CAPABILITY_LMASTER" != "no" ] || {
2008-05-06 04:41:22 +04:00
CTDB_OPTIONS="$CTDB_OPTIONS --no-lmaster"
}
2008-07-10 04:37:22 +04:00
[ -z "$CTDB_LVS_PUBLIC_IP" ] || {
CTDB_OPTIONS="$CTDB_OPTIONS --lvs"
}
2008-10-17 02:02:03 +04:00
[ -z "$CTDB_SCRIPT_LOG_LEVEL" ] || {
CTDB_OPTIONS="$CTDB_OPTIONS --script-log-level=$CTDB_SCRIPT_LOG_LEVEL"
}
2007-05-28 00:48:18 +04:00
2008-07-04 10:58:14 +04:00
if [ "$CTDB_VALGRIND" = "yes" ]; then
init_style="valgrind"
else if [ -x /sbin/startproc ]; then
2007-06-01 17:25:33 +04:00
init_style="suse"
2007-06-03 13:24:52 +04:00
else if [ -x /sbin/start-stop-daemon ]; then
init_style="ubuntu"
else
init_style="redhat"
fi
2007-06-01 17:25:33 +04:00
fi
2008-07-04 10:58:14 +04:00
fi
2007-06-01 17:25:33 +04:00
2008-12-12 18:04:29 +03:00
reset_retval() {
return $1
}
2007-05-28 00:48:18 +04:00
start() {
2007-06-02 13:40:07 +04:00
killall -q ctdbd
2007-06-01 17:25:33 +04:00
echo -n $"Starting ctdbd service: "
2008-05-12 10:44:33 +04:00
# check all persistent databases that they look ok
PERSISTENT_DB_DIR="/var/ctdb/persistent"
[ -z "$CTDB_DBDIR" ] || {
PERSISTENT_DB_DIR="$CTDB_DBDIR/persistent"
}
2008-05-16 09:14:17 +04:00
mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
2008-05-12 10:44:33 +04:00
/usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
echo "Persistent database $PDBASE is corrupted! CTDB will not start."
return 1
}
done
2007-06-01 17:25:33 +04:00
case $init_style in
2008-07-04 10:58:14 +04:00
valgrind)
valgrind -q --log-file=/var/log/ctdb_valgrind /usr/sbin/ctdbd --nosetsched $CTDB_OPTIONS
RETVAL=0
;;
2007-06-01 17:25:33 +04:00
suse)
2007-06-03 11:53:26 +04:00
startproc /usr/sbin/ctdbd $CTDB_OPTIONS
2007-06-01 17:25:33 +04:00
rc_status -v
2008-01-04 04:41:53 +03:00
RETVAL=$?
2007-06-01 17:25:33 +04:00
;;
redhat)
daemon ctdbd $CTDB_OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
;;
2007-06-03 13:24:52 +04:00
ubuntu)
start-stop-daemon --start --quiet --background --exec /usr/sbin/ctdbd -- $CTDB_OPTIONS
2008-01-04 04:41:53 +03:00
RETVAL=$?
2007-06-03 13:24:52 +04:00
;;
2007-06-01 17:25:33 +04:00
esac
2008-01-04 04:41:53 +03:00
sleep 1
# 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
return $RETVAL
2007-05-28 00:48:18 +04:00
}
stop() {
2007-06-01 17:25:33 +04:00
echo -n $"Shutting down ctdbd service: "
2008-12-12 18:00:07 +03:00
ctdb ping >& /dev/null || {
echo -n " Warning: ctdbd not running ! "
case $init_style in
suse)
rc_status -v
;;
redhat)
echo ""
;;
esac
return 0
}
2007-05-29 09:36:42 +04:00
ctdb shutdown
2007-05-28 00:48:18 +04:00
RETVAL=$?
2007-09-14 03:25:11 +04:00
count=0
2008-07-04 10:58:14 +04:00
if [ "$init_style" = "valgrind" ]; then
# very crude method
sleep 2
pkill -9 -f valgrind
fi
2007-09-14 03:25:11 +04:00
while killall -q -0 ctdbd; do
sleep 1
count=`expr $count + 1`
[ $count -gt 10 ] && {
echo -n $"killing ctdbd "
killall -q -9 ctdbd
2007-09-14 08:14:03 +04:00
pkill -9 -f $CTDB_BASE/events.d/
2007-09-14 03:25:11 +04:00
}
done
2007-06-01 17:25:33 +04:00
case $init_style in
suse)
2008-12-12 18:04:29 +03:00
# re-set the return code to the recorded RETVAL
# in order to print the correct status message
set_retval $RETVAL
2007-06-01 17:25:33 +04:00
rc_status -v
;;
redhat)
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
echo ""
;;
esac
2008-12-12 18:05:04 +03:00
return $RETVAL
2007-05-28 00:48:18 +04:00
}
restart() {
stop
start
}
2007-06-01 17:25:33 +04:00
status() {
2008-12-12 18:57:58 +03:00
echo -n $"Checking for ctdbd service: "
ctdb ping >& /dev/null || {
RETVAL=$?
echo -n " ctdbd not running. "
case $init_style in
suse)
set_retval $RETVAL
rc_status -v
;;
redhat)
echo ""
;;
esac
return $RETVAL
}
echo ""
2007-05-29 09:36:42 +04:00
ctdb status
2007-05-28 00:48:18 +04:00
}
case "$1" in
start)
start
;;
stop)
stop
;;
2008-08-25 04:03:16 +04:00
restart|reload)
2007-05-28 00:48:18 +04:00
restart
;;
status)
2007-06-02 12:51:05 +04:00
status
2007-05-28 00:48:18 +04:00
;;
condrestart)
2007-06-01 17:25:33 +04:00
ctdb status > /dev/null && restart || :
2007-05-28 00:48:18 +04:00
;;
2007-06-02 12:51:05 +04:00
cron)
# 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
;;
2007-05-28 00:48:18 +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 $?