From 8e2ed2e8acb406bc525e530afb15b1dceacbe2d9 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 28 Mar 2012 19:00:49 +0200 Subject: [PATCH] =?UTF-8?q?ganeti.initd:=20Add=20=E2=80=9Cstatus=E2=80=9D?= =?UTF-8?q?=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eric Rostetter sent a patch adding a βstatusβ action, but unfortunately his code was apparently specific to Red Hat. I hope this implementation is more distribution-agnostic; after all βstatus_of_procβ is part of LSB. Example output: $ /etc/init.d/ganeti status ganeti-noded is not running ... failed! ganeti-masterd is running. ganeti-rapi is running. ganeti-confd is running. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- daemons/daemon-util.in | 26 +++++++++++++++++++++++++- doc/examples/ganeti.initd.in | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in index 819fd6bb5..789487d0e 100644 --- a/daemons/daemon-util.in +++ b/daemons/daemon-util.in @@ -1,7 +1,7 @@ #!/bin/bash # -# Copyright (C) 2009 Google Inc. +# Copyright (C) 2009, 2012 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -108,6 +108,30 @@ check_exitcode() { return 0 } +# Prints path to PID file for a daemon. +daemon_pidfile() { + if [[ "$#" -lt 1 ]]; then + echo 'Missing daemon name.' >&2 + return 1 + fi + + local name="$1"; shift + + _daemon_pidfile $name +} + +# Prints path to daemon executable. +daemon_executable() { + if [[ "$#" -lt 1 ]]; then + echo 'Missing daemon name.' >&2 + return 1 + fi + + local name="$1"; shift + + _daemon_executable $name +} + # Prints a list of all daemons in the order in which they should be started list_start_daemons() { local name diff --git a/doc/examples/ganeti.initd.in b/doc/examples/ganeti.initd.in index 94be6daef..cba7fb91b 100644 --- a/doc/examples/ganeti.initd.in +++ b/doc/examples/ganeti.initd.in @@ -75,6 +75,30 @@ stop_all() { 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 @@ -94,6 +118,9 @@ case "$1" in stop_all "$2" start_all "$2" ;; + status) + status_all "$2" + ;; *) log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}" exit 1 -- GitLab