--- b-ctdb.init 2009-07-17 22:33:54.000000000 +0200 +++ debian/ctdb.init 2009-07-17 23:01:39.000000000 +0200 @@ -3,7 +3,7 @@ ############################## # ctdb: Starts the clustered tdb daemon # -# chkconfig: - 90 01 +# chkconfig: - 90 36 # # description: Starts and stops the clustered tdb daemon # pidfile: /var/run/ctdbd/ctdbd.pid @@ -11,14 +11,66 @@ ### BEGIN INIT INFO # Provides: ctdb -# Required-Start: $network -# Required-Stop: $network -# Default-Stop: -# Default-Start: 3 5 +# Required-Start: $network $local_fs $remote_fs +# Required-Stop: $network $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 # Short-Description: start and stop ctdb service # Description: initscript for the ctdb service ### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +NAME=ctdb +DESC="Clustered TDB" + +#LSB +if [ -f /lib/lsb/init-functions ] ; then + . /lib/lsb/init-functions +fi +if ! type 'log_daemon_msg' >/dev/null; then + log_daemon_msg () { + if [ -z "${1:-}" ]; then + return 1 + fi + + if [ -z "${2:-}" ]; then + echo -n "$1:" + return + fi + + echo -n "$1: $2" + } +fi +if ! type 'log_progress_msg' >/dev/null; then + log_progress_msg () { + if [ -z "${1:-}" ]; then + return 1 + fi + echo -n " $@" + } +fi +if ! type 'log_end_msg' >/dev/null; then + log_end_msg () { + # If no arguments were passed, return + if [ -z "${1:-}" ]; then + return 1 + fi + + retval=$1 + + if [ $1 -eq 0 ]; then + echo "." + elif [ $1 -eq 255 ]; then + /bin/echo -e " (warning)." + else + /bin/echo -e " failed!" + fi + return $retval + } +fi + # Source function library. if [ -f /etc/init.d/functions ] ; then . /etc/init.d/functions @@ -26,6 +78,16 @@ . /etc/rc.d/init.d/functions fi +#gettext +if [ -f /usr/bin/gettext.sh ] ; then + . /usr/bin/gettext.sh +fi +if ! type 'eval_gettext' >/dev/null; then + eval_gettext() { + echo -n "$1" | (export PATH `envsubst --variables "$1"`; envsubst "$1") + } +fi + [ -f /etc/rc.status ] && { . /etc/rc.status rc_reset @@ -43,6 +105,8 @@ loadconfig network loadconfig ctdb +set -e + [ -z "$CTDB_RECOVERY_LOCK" ] && { echo "No recovery lock specified. Starting CTDB without split brain prevention" } @@ -55,6 +119,8 @@ ctdbd=${CTDBD:-/usr/sbin/ctdbd} +test -x $ctdbd || exit 0 + if [ "$CTDB_VALGRIND" = "yes" ]; then init_style="valgrind" else @@ -102,6 +168,7 @@ maybe_set "-d" "$CTDB_DEBUGLEVEL" 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 "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no" maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no" maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP" @@ -109,7 +176,10 @@ } check_persistent_databases () { - PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent" + case $init_style in + ubuntu) PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/lib/ctdb}/persistent" ;; + *) PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent" ;; + esac 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 || { @@ -133,16 +203,12 @@ return $1 } -ctdbd=${CTDBD:-/usr/sbin/ctdbd} - -start() { - echo -n $"Starting ctdbd service: " - - ctdb ping >/dev/null 2>&1 && { - echo $"CTDB is already running" - return 1 +running() { + pkill -0 -f $ctdbd || return 1 + return 0 } +start_server() { build_ctdb_options check_persistent_databases || return $? @@ -179,28 +245,19 @@ return $RETVAL } -stop() { - echo -n $"Shutting down ctdbd service: " - pkill -0 -f $ctdbd || { - echo -n " Warning: ctdbd not running ! " - case $init_style in - suse) - rc_status -v - ;; - redhat) - echo "" - ;; - esac - return 0 - } +stop_server() { ctdb shutdown >/dev/null 2>&1 RETVAL=$? count=0 + if [ "$init_style" = "ubuntu" ]; then + start-stop-daemon --stop --quiet --exec $ctdbd + RETVAL=$? + fi while pkill -0 -f $ctdbd ; do sleep 1 - count=$(($count + 1)) + count=`expr $count + 1` [ $count -gt 10 ] && { - echo -n $"killing ctdbd " + eval_gettext "killing ctdbd " pkill -9 -f $ctdbd pkill -9 -f $CTDB_BASE/events.d/ } @@ -221,55 +278,84 @@ return $RETVAL } -restart() { - stop - 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) - echo "" - ;; - esac - return $RETVAL - } - echo "" - ctdb status -} - - case "$1" in start) - start + log_daemon_msg "Starting $DESC " "$NAME" + # Check if it's running first + if running ; then + log_progress_msg "already running" + log_end_msg 0 + exit 0 + fi + if start_server && running ; then + # It's ok, the server started and is running + log_end_msg 0 + else + # Either we could not start it or it is not running + # after we did + log_end_msg 1 + fi ;; stop) - stop + log_daemon_msg "Stopping $DESC" "$NAME" + if running ; then + # Only stop the server if we see it running + stop_server + log_end_msg $? + else + # If it's not running don't do anything + log_progress_msg "not running" + log_end_msg 0 + exit 0 + fi ;; - restart|reload) - restart + restart|reload|force-reload) + log_daemon_msg "Restarting $DESC" "$NAME" + running && stop_server + start_server + running + log_end_msg $? ;; status) - status + log_daemon_msg "Checking status of $DESC" "$NAME" + if running ; then + log_progress_msg "running" + echo + ctdb status + log_end_msg 0 + else + log_progress_msg "not running" + log_end_msg 1 + exit 1 + fi ;; condrestart) - ctdb status > /dev/null && restart || : + if running ; then + log_daemon_msg "Restarting $DESC" "$NAME" + stop_server + start_server + log_end_msg $? + fi ;; cron) # used from cron to auto-restart ctdb - ctdb status > /dev/null || restart + if ! running ; then + log_daemon_msg "Starting $DESC " "$NAME" + if start_server && running ; then + # It's ok, the server started and is running + log_end_msg 0 + else + # Either we could not start it or it is not running + # after we did + log_end_msg 1 + fi + fi ;; *) - echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}" + eval_gettext "Usage: $0 {start|stop|restart|status|cron|condrestart}" >&2 + echo >&2 exit 1 + ;; esac exit $?