From 10c5c1c3f73fd445f22a6806d45063a06ba440c1 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 11 Mar 2010 12:51:44 +0100
Subject: [PATCH] ganeti.initd: Move code checking daemon exit code to
 daemon-util
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is again for re-using code.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 daemons/daemon-util.in       | 23 +++++++++++++++++++++++
 doc/examples/ganeti.initd.in | 18 +++++++-----------
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in
index 5d7e89b03..05e97b47e 100755
--- a/daemons/daemon-util.in
+++ b/daemons/daemon-util.in
@@ -51,6 +51,29 @@ check_config() {
   return 0
 }
 
+# Checks the exit code of a daemon
+check_exitcode() {
+  if [[ "$#" -lt 1 ]]; then
+    echo 'Missing exit code.' >&2
+    return 1
+  fi
+
+  local rc="$1"; shift
+
+  case "$rc" in
+    0) ;;
+    11)
+      echo "not master"
+    ;;
+    *)
+      echo "exit code $rc"
+      return 1
+    ;;
+  esac
+
+  return 0
+}
+
 # Checks whether daemon is running
 check() {
   if [[ "$#" -lt 1 ]]; then
diff --git a/doc/examples/ganeti.initd.in b/doc/examples/ganeti.initd.in
index 5ad3a9ba2..617d06df9 100644
--- a/doc/examples/ganeti.initd.in
+++ b/doc/examples/ganeti.initd.in
@@ -29,17 +29,13 @@ test -f "@PREFIX@/sbin/$NODED" || exit 0
 
 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() {
-- 
GitLab