Commit 8e2ed2e8 authored by Michael Hanselmann's avatar Michael Hanselmann

ganeti.initd: Add “status” action

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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent c9c33a28
#!/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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment