Merge branch 'init_rewrite'
authorMartin Schwenke <martin@meltin.net>
Tue, 2 Jun 2009 06:40:01 +0000 (16:40 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 2 Jun 2009 06:40:01 +0000 (16:40 +1000)
Conflicts:
config/ctdb.init

Signed-off-by: Martin Schwenke <martin@meltin.net>
1  2 
config/ctdb.init

index 4076c5be8bba3216bd57f4e3fff10a99e94e2d4d,723c166ed74976209dfc0bb5d111332094563509..5cac0351b5c58b272ce6f22a4634cf5cc507f03a
@@@ -83,107 -49,184 +49,184 @@@ loadconfig ctd
  detect_init_style
  export CTDB_INIT_STYLE
  
- if [ "x$CTDB_VALGRIND" = "xyes" ]; then
-       init_style="valgrind"
+ ctdbd=${CTDBD:-/usr/sbin/ctdbd}
+ if [ "$CTDB_VALGRIND" = "yes" ]; then
+     init_style="valgrind"
  else
-       init_style="$CTDB_INIT_STYLE"
+     init_style="$CTDB_INIT_STYLE"
  fi
  
- set_retval() {
-       return $1
+ 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.
+       # 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}"
+     }
+     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"
+     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"
  }
  
- ctdbd=${CTDBD:-/usr/sbin/ctdbd}
+ 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
+ }
+ set_retval() {
+     return $1
+ }
  
  start() {
-       echo -n $"Starting ctdbd service: "
-       ctdb ping >& /dev/null
-       if [ $? == "0" ] ; then
-               echo $"CTDB is already running"
-               RETVAL=1
-               return $RETVAL
-         fi
-       # check all persistent databases that they look ok
-       PERSISTENT_DB_DIR="/var/ctdb/persistent"
-       [ -z "$CTDB_DBDIR" ] || {
-               PERSISTENT_DB_DIR="$CTDB_DBDIR/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
+     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 $?
+     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
+           ;;
+       ubuntu)
+           start-stop-daemon --start --quiet --background \
+               --exec $ctdbd -- $CTDB_OPTIONS
+           RETVAL=$?
+           ;;
+     esac
+     sleep 1
+     set_ctdb_variables
+     return $RETVAL
+ }     
+ stop() {
+     echo -n $"Shutting down ctdbd service: "
+     pkill -0 -f $ctdbd || {
+       echo -n "  Warning: ctdbd not running ! "
        case $init_style in
-           valgrind)
-               valgrind -q --log-file=/var/log/ctdb_valgrind \
-                   $ctdbd --nosetsched $CTDB_OPTIONS 
-               RETVAL=0
-               ;;
            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
-               ;;
-           ubuntu)
-               start-stop-daemon --start --quiet --background \
-                   --exec $ctdbd -- $CTDB_OPTIONS
-               RETVAL=$?
+               echo ""
                ;;
        esac
+       return 0
+     }
+     ctdb shutdown >/dev/null 2>&1
+     RETVAL=$?
+     count=0
+     while pkill -0 -f $ctdbd ; do
        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
+       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)
+           echo
+           [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
+           echo ""
+           ;;
+     esac
+     return $RETVAL
+ }
  
-       return $RETVAL
- }     
+ restart() {
+     stop
+     start
 -}     
++}
  
- 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
-       }
-       ctdb shutdown >/dev/null 2>&1
+ status() {
+     echo -n $"Checking for ctdbd service: "
+     ctdb ping >/dev/null 2>&1 || {
        RETVAL=$?
-       count=0
-       while pkill -0 -f $ctdbd ; do
-           sleep 1
-           count=$(($count + 1))
-           [ $count -gt 10 ] && {
-               echo -n $"killing ctdbd "
-               pkill -9 -f $ctdbd
-               pkill -9 -f $CTDB_BASE/events.d/
-           }
-       done
+       echo -n "  ctdbd not running. "
        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
                ;;