New version 1.2.15
[sahlberg/ctdb.git] / config / ctdb.init
index 5cac0351b5c58b272ce6f22a4634cf5cc507f03a..25e158fcc5382abb6ce7f9266991f4854df45b51 100755 (executable)
@@ -39,6 +39,10 @@ unset TMPDIR
     export CTDB_BASE="/etc/ctdb"
 }
 
+[ -z "$CTDB_VARDIR" ] && {
+    export CTDB_VARDIR="/var/ctdb"
+}
+
 . $CTDB_BASE/functions
 loadconfig network
 loadconfig ctdb
@@ -58,10 +62,6 @@ else
 fi
 
 build_ctdb_options () {
-    [ -z "$CTDB_RECOVERY_LOCK" ] && {
-       echo "You must configure the location of the CTDB_RECOVERY_LOCK"
-       exit 1
-    }
 
     maybe_set () {
        # If the 2nd arg is null then return - don't set anything.
@@ -69,7 +69,7 @@ build_ctdb_options () {
        # then return
        [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
 
-       val="$2"
+       val="'$2'"
        case "$1" in
            --*) sep="=" ;;
            -*)  sep=" " ;;
@@ -83,6 +83,9 @@ build_ctdb_options () {
        CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
     }
 
+    [ -z "$CTDB_RECOVERY_LOCK" ] && {
+        echo "No recovery lock specified. Starting CTDB without split brain prevention"
+    }
     maybe_set "--reclock"                "$CTDB_RECOVERY_LOCK"
 
     # build up CTDB_OPTIONS variable from optional parameters
@@ -98,17 +101,53 @@ build_ctdb_options () {
     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"
     maybe_set "--script-log-level"       "$CTDB_SCRIPT_LOG_LEVEL"
+    maybe_set "--log-ringbuf-size"       "$CTDB_LOG_RINGBUF_SIZE"
+    maybe_set "--syslog"                 "$CTDB_SYSLOG"               "yes"
+    maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
+}
+
+check_tdb () {
+       local PDBASE=$1
+
+       local TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
+
+       test x"$TDBTOOL_HAS_CHECK" = x"1" && {
+               #
+               # Note tdbtool always exits with 0
+               #
+               local OK=`/usr/bin/tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
+               test x"$OK" = x"1" || {
+                       return 1;
+               }
+
+               return 0;
+       }
+
+       /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
+               return $?;
+       }
+
+       return 0;
 }
 
 check_persistent_databases () {
     PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
     mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
+    local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
+
+    test -z "$ERRCOUNT" && {
+       ERRCOUNT="0"
+    }
+    test x"$ERRCOUNT" != x"0" && {
+       return 0;
+    }
     for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
-       /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
+       check_tdb $PDBASE || {
            echo "Persistent database $PDBASE is corrupted! CTDB will not start."
            return 1
        }
@@ -129,49 +168,84 @@ set_retval() {
     return $1
 }
 
+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
+}
+
+ctdbd=${CTDBD:-/usr/sbin/ctdbd}
+
 start() {
     echo -n $"Starting ctdbd service: "
 
     ctdb ping >/dev/null 2>&1 && {
        echo $"CTDB is already running"
-       return 1
+       return 0
     }
 
     build_ctdb_options
 
     check_persistent_databases || return $?
 
+    if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
+       ulimit -c 0
+    else
+       ulimit -c unlimited
+    fi
+
     case $init_style in
        valgrind)
-           valgrind -q --log-file=/var/log/ctdb_valgrind \
-               $ctdbd --nosetsched $CTDB_OPTIONS 
+           eval valgrind -q --log-file=/var/log/ctdb_valgrind \
+               $ctdbd --valgrinding "$CTDB_OPTIONS"
            RETVAL=$?
            echo
            ;;
        suse)
-           startproc $ctdbd $CTDB_OPTIONS
-           rc_status -v
+           eval startproc $ctdbd "$CTDB_OPTIONS"
            RETVAL=$?
            ;;
        redhat)
-           daemon $ctdbd $CTDB_OPTIONS
+           eval $ctdbd "$CTDB_OPTIONS"
            RETVAL=$?
-           echo
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
            ;;
-       ubuntu)
-           start-stop-daemon --start --quiet --background \
-               --exec $ctdbd -- $CTDB_OPTIONS
+       debian)
+           eval start-stop-daemon --start --quiet --background \
+               --exec $ctdbd -- "$CTDB_OPTIONS"
            RETVAL=$?
            ;;
     esac
 
-    sleep 1
+    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
 
-    set_ctdb_variables
+    case $init_style in
+       suse)
+           set_retval $RETVAL
+           rc_status -v
+           ;;
+       redhat)
+           [ $RETVAL -eq 0 ] && success || failure
+           echo
+           ;;
+    esac
 
     return $RETVAL
-}      
+}
 
 stop() {
     echo -n $"Shutting down ctdbd service: "
@@ -207,7 +281,7 @@ stop() {
            rc_status -v
            ;;
        redhat)
-           echo
+            [ $RETVAL -eq 0 ] && success || failure
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
            echo ""
            ;;
@@ -231,7 +305,13 @@ status() {
                rc_status -v
                ;;
            redhat)
-               echo ""
+               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
@@ -248,13 +328,13 @@ case "$1" in
     stop)
        stop
        ;;
-    restart|reload)
+    restart|reload|force-reload)
        restart
        ;;
     status)
        status
        ;;
-    condrestart)
+    condrestart|try-restart)
        ctdb status > /dev/null && restart || :
        ;;
     cron)
@@ -262,7 +342,7 @@ case "$1" in
        ctdb status > /dev/null || restart
        ;;
     *)
-       echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
+       echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
        exit 1
 esac