X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/a533e97517d00183005b5ddb44de80aa2d26ea59..1118ec441ed2152d7a611e608c5a8addea438333:/doc/examples/ganeti.initd.in diff --git a/doc/examples/ganeti.initd.in b/doc/examples/ganeti.initd.in index 8ca98ea..cd137bd 100644 --- a/doc/examples/ganeti.initd.in +++ b/doc/examples/ganeti.initd.in @@ -3,112 +3,96 @@ # based on skeleton from Debian GNU/Linux ### BEGIN INIT INFO # Provides: ganeti -# Required-Start: $syslog $remote_fs xend -# Required-Stop: $syslog $remote_fs xend +# Required-Start: $syslog $remote_fs +# Required-Stop: $syslog $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: Ganeti Xen Cluster Manager -# Description: Ganeti Xen Cluster Manager +# Short-Description: Ganeti Cluster Manager +# Description: Ganeti Cluster Manager ### END INIT INFO 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_NAME="ganeti-noded" -NODED="@PREFIX@/sbin/${NODED_NAME}" -NODED_PID="${GANETIRUNDIR}/${NODED_NAME}.pid" - -MASTERD_NAME="ganeti-masterd" -MASTERD="@PREFIX@/sbin/${MASTERD_NAME}" -MASTERD_PID="${GANETIRUNDIR}/${MASTERD_NAME}.pid" - -RAPI_NAME="ganeti-rapi" -RAPI="@PREFIX@/sbin/${RAPI_NAME}" -RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid" +DAEMON_UTIL=@PKGLIBDIR@/daemon-util SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti" -test -f $NODED || exit 0 +test -f "$DAEMON_UTIL" || exit 0 . /lib/lsb/init-functions -if [ -s $GANETI_DEFAULTS_FILE ]; then - . $GANETI_DEFAULTS_FILE -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 pidfile - local daemon="$1"; shift - local pidfile="$1"; shift + # called as start_action daemon-name + local daemon="$1" log_action_begin_msg "$daemon" - start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \ - -- "$@" + $DAEMON_UTIL start "$@" check_exitcode $? } stop_action() { - # called as stop_action daemon pidfile - log_action_begin_msg "$1" - start-stop-daemon --stop --quiet --oknodo \ - --retry 30 --pidfile "$2" + # called as stop_action daemon-name + local daemon="$1" + log_action_begin_msg "$daemon" + $DAEMON_UTIL stop "$@" check_exitcode $? } +maybe_do() { + requested="$1"; shift + action="$1"; shift + target="$1" + if [ -z "$requested" -o "$requested" = "$target" ]; then + $action "$@" + fi +} + +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 +} + +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" "$NAME" - check_config - start_action $NODED $NODED_PID - start_action $MASTERD $MASTERD_PID - start_action $RAPI $RAPI_PID + log_daemon_msg "Starting $DESC" "$2" + start_all "$2" ;; stop) - log_daemon_msg "Stopping $DESC" "$NAME" - stop_action $RAPI $RAPI_PID - stop_action $MASTERD $MASTERD_PID - stop_action $NODED $NODED_PID + log_daemon_msg "Stopping $DESC" "$2" + stop_all "$2" ;; restart|force-reload) - log_daemon_msg "Reloading $DESC" - stop_action $RAPI $RAPI_PID - stop_action $MASTERD $MASTERD_PID - stop_action $NODED $NODED_PID - check_config - start_action $NODED $NODED_PID - start_action $MASTERD $MASTERD_PID - start_action $RAPI $RAPI_PID + log_daemon_msg "Restarting $DESC" "$2" + stop_all "$2" + start_all "$2" ;; *) log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"