config: let 13.per_ip_routing use a flock for generate_auto_link_local()
[metze/ctdb/wip.git] / config / ctdb.init
index 95e8ccc5c663705641c0aade52674933c26292c1..7dfdd26639c70cb4fe29a30cf5a28a05cb630d70 100755 (executable)
@@ -43,10 +43,6 @@ unset TMPDIR
 loadconfig network
 loadconfig ctdb
 
-[ -z "$CTDB_RECOVERY_LOCK" ] && {
-    echo "No recovery lock specified. Starting CTDB without split brain prevention"
-}
-
 # check networking is up (for redhat)
 [ "$NETWORKING" = "no" ] && exit 0
 
@@ -62,10 +58,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.
@@ -73,7 +65,7 @@ build_ctdb_options () {
        # then return
        [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
 
-       val="$2"
+       val="'$2'"
        case "$1" in
            --*) sep="=" ;;
            -*)  sep=" " ;;
@@ -87,6 +79,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
@@ -102,17 +97,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
        }
@@ -140,34 +171,41 @@ start() {
 
     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
+           eval startproc $ctdbd "$CTDB_OPTIONS"
            rc_status -v
            RETVAL=$?
            ;;
        redhat)
-           daemon $ctdbd $CTDB_OPTIONS
+           eval $ctdbd "$CTDB_OPTIONS"
            RETVAL=$?
+           [ $RETVAL -eq 0 ] && success || failure
            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
@@ -177,7 +215,7 @@ start() {
     set_ctdb_variables
 
     return $RETVAL
-}      
+}
 
 stop() {
     echo -n $"Shutting down ctdbd service: "
@@ -213,7 +251,7 @@ stop() {
            rc_status -v
            ;;
        redhat)
-           echo
+            [ $RETVAL -eq 0 ] && success || failure
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
            echo ""
            ;;
@@ -224,7 +262,7 @@ stop() {
 restart() {
     stop
     start
-}      
+}
 
 status() {
     echo -n $"Checking for ctdbd service: "
@@ -237,7 +275,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
@@ -254,13 +298,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)
@@ -268,7 +312,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