Update man page of gnt-cluster regarding file-storage-dir
[ganeti-local] / doc / examples / ganeti.initd.in
index 235f84a..f16d35b 100644 (file)
@@ -1,6 +1,8 @@
 #!/bin/sh
-# ganeti node daemon starter script
-# based on skeleton from Debian GNU/Linux
+# ganeti daemons init script
+#
+# chkconfig: 2345 99 01
+# description: Ganeti Cluster Manager
 ### BEGIN INIT INFO
 # Provides:          ganeti
 # Required-Start:    $syslog $remote_fs
 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
 DESC="Ganeti cluster"
 
-GANETIRUNDIR="@LOCALSTATEDIR@/run/ganeti"
-
-GANETI_DEFAULTS_FILE="@SYSCONFDIR@/default/ganeti"
-
-NODED="ganeti-noded"
-NODED_ARGS=""
-
-MASTERD="ganeti-masterd"
-MASTERD_ARGS=""
-
-CONFD="ganeti-confd"
-CONFD_ARGS=""
-
-RAPI="ganeti-rapi"
-RAPI_ARGS=""
+DAEMON_UTIL=@PKGLIBDIR@/daemon-util
 
 SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
 
-test -f "@PREFIX@/sbin/$NODED" || exit 0
-
-. /lib/lsb/init-functions
+test -f "$DAEMON_UTIL" || exit 0
 
-if [ -s $GANETI_DEFAULTS_FILE ]; then
-    . $GANETI_DEFAULTS_FILE
+if [ -r /lib/lsb/init-functions ]; then
+  . /lib/lsb/init-functions
+elif [ -r /etc/rc.d/init.d/functions ]; then
+  . /etc/rc.d/init.d/functions
+else
+  echo "Unable to find init functions"
+  exit 1
 fi
 
-check_config() {
-    for fname in \
-        "@LOCALSTATEDIR@/lib/ganeti/server.pem"
-    do
-        if ! [ -f "$fname" ]; then
-            log_end_msg 0
-            log_warning_msg "Config $fname not there, will not run."
-            exit 0
-        fi
-    done
-}
-
 check_exitcode() {
     RC=$1
-    case $RC in
-        0)
-            log_action_end_msg 0
-            ;;
-        11)
-            log_action_end_msg 0 "not master"
-            ;;
-        *)
-            log_action_end_msg 1 "exit code $RC"
-            ;;
-    esac
+
+    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
+    then
+        log_action_end_msg 0 "$errmsg"
+    else
+        log_action_end_msg 1 "$errmsg"
+    fi
 }
 
 start_action() {
     # called as start_action daemon-name
-    local daemon="$1"; shift
+    local daemon="$1"
     log_action_begin_msg "$daemon"
-    start-stop-daemon --start --quiet \
-        --pidfile "${GANETIRUNDIR}/${daemon}.pid" \
-        --startas "@PREFIX@/sbin/$daemon" \
-        --oknodo \
-        -- "$@"
+    $DAEMON_UTIL start "$@"
     check_exitcode $?
 }
 
@@ -83,8 +54,7 @@ stop_action() {
     # called as stop_action daemon-name
     local daemon="$1"
     log_action_begin_msg "$daemon"
-    start-stop-daemon --stop --quiet --oknodo \
-        --retry 30 --pidfile "${GANETIRUNDIR}/${daemon}.pid"
+    $DAEMON_UTIL stop "$@"
     check_exitcode $?
 }
 
@@ -97,40 +67,68 @@ maybe_do() {
     fi
 }
 
-if [ -n "$2" -a \
-    "$2" != "$NODED" -a \
-    "$2" != "$MASTERD" -a \
-    "$2" != "$RAPI" ]; then
-    log_failure_msg "Unknown daemon '$2' requested"
+start_all() {
+    if ! $DAEMON_UTIL check-config; then
+        log_warning_msg "Incomplete configuration, will not run."
+        exit 0
+    fi
+
+    for i in $($DAEMON_UTIL list-start-daemons); do
+        maybe_do "$1" start_action $i
+    done
+}
+
+stop_all() {
+    for i in $($DAEMON_UTIL list-stop-daemons); do
+        maybe_do "$1" stop_action $i
+    done
+}
+
+status_all() {
+    local daemons="$1" status ret
+
+    if [ -z "$daemons" ]; then
+      daemons=$($DAEMON_UTIL list-start-daemons)
+    fi
+
+    status=0
+
+    for i in $daemons; do
+      if status_of_proc $($DAEMON_UTIL daemon-executable $i) $i; then
+          ret=0
+      else
+          ret=$?
+          # Use exit code from first failed call
+          if [ "$status" -eq 0 ]; then
+              status=$ret
+          fi
+      fi
+    done
+
+    exit $status
+}
+
+if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
+    log_failure_msg "$errmsg"
     exit 1
 fi
 
 case "$1" in
     start)
         log_daemon_msg "Starting $DESC" "$2"
-        check_config
-        maybe_do "$2" start_action $NODED $NODED_ARGS
-        maybe_do "$2" start_action $MASTERD $MASTERD_ARGS
-        maybe_do "$2" start_action $CONFD $CONFD_ARGS
-        maybe_do "$2" start_action $RAPI $RAPI_ARGS
+        start_all "$2"
         ;;
     stop)
         log_daemon_msg "Stopping $DESC" "$2"
-        maybe_do "$2" stop_action $RAPI
-        maybe_do "$2" stop_action $CONFD
-        maybe_do "$2" stop_action $MASTERD
-        maybe_do "$2" stop_action $NODED
+        stop_all "$2"
         ;;
     restart|force-reload)
-        maybe_do "$2" stop_action $RAPI
-        maybe_do "$2" stop_action $CONFD
-        maybe_do "$2" stop_action $MASTERD
-        maybe_do "$2" stop_action $NODED
-        check_config
-        maybe_do "$2" start_action $NODED $NODED_ARGS
-        maybe_do "$2" start_action $MASTERD $MASTERD_ARGS
-        maybe_do "$2" start_action $CONFD $CONFD_ARGS
-        maybe_do "$2" start_action $RAPI $RAPI_ARGS
+        log_daemon_msg "Restarting $DESC" "$2"
+        stop_all "$2"
+        start_all "$2"
+        ;;
+    status)
+        status_all "$2"
         ;;
     *)
         log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"