[one-users] Patch to opennebula-3.8.1/share/scripts/one to allow checking the daemons' status

Simon J Mudd sjmudd at pobox.com
Sat Jan 5 04:47:23 PST 2013


Hi,

I'm not sure the right forum to provide this so hope sending to the list is ok.
One thing I found when initially trying to setup OpenNebula is that you can start and
stop the daemons but you can not check if they are running. Most "init scripts" allow
you to provide a status.

This small patch provides that functionality. Perhaps it can be included?

$ diff -u opennebula-3.8.1/share/scripts/one{.orig,}
--- opennebula-3.8.1/share/scripts/one.orig     2013-01-05 13:38:50.846539319 +0100
+++ opennebula-3.8.1/share/scripts/one  2013-01-05 13:39:08.110451396 +0100
@@ -181,6 +181,38 @@
 }
 
 #------------------------------------------------------------------------------
+# Function that checks if the daemons are running
+#------------------------------------------------------------------------------
+status()
+{
+    if [ -f $ONE_PID ]; then
+        PID=$(cat $ONE_PID)
+        RESULT=$(/usr/bin/ps --no-heading -p $PID)
+
+        if [ -z "$RESULT" ]; then
+            echo "DOWN: $ONED seems not to be running, $ONE_PID thinks it has pid $PID"
+        else
+            echo "UP: Found $ONED running with PID $PID"
+        fi
+    else
+        echo "DOWN: $ONE_PID does not exist."
+    fi
+
+    if [ -f $ONE_SCHEDPID ]; then
+        PID=$(cat $ONE_SCHEDPID)
+        RESULT=$(/usr/bin/ps --no-heading -p $PID)
+
+        if [ -z "$RESULT" ]; then
+            echo "DOWN: $ONE_SCHEDULER seems not to be running, $ONE_SCHEDPID thinks it has pid $PID"
+        else
+            echo "UP: Found $ONE_SCHEDULER running with PID $PID"
+        fi
+    else
+        echo "DOWN: $ONE_SCHEDPID does not exist."
+    fi
+}
+
+#------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 
 if [ "$1" = "-f" ]; then
@@ -197,8 +229,12 @@
         stop
         echo "oned and scheduler stopped"
         ;;
+    status)
+        # Check if everything is working.
+        status
+        ;;
     *)
-        echo "Usage: one [-f] {start|stop}" >&2
+        echo "Usage: one [-f] {start|stop|status}" >&2
         echo "Options:" >&2
         echo "  -f  Do not backup log file." >&2
         exit 3
$

On the server I'm trying to get OpenNebula working on I see this:

[oneadmin at myhost ~]$ opennebula-3.8.1/share/scripts/one status
UP: Found /usr/bin/oned running with PID 424
UP: Found /usr/bin/mm_sched running with PID 425
[oneadmin at myhost ~]$ one stop
oned and scheduler stopped
[oneadmin at myhost src]$ opennebula-3.8.1/share/scripts/one status
DOWN: /var/run/one/oned.pid does not exist.
DOWN: /var/run/one/sched.pid does not exist.
[oneadmin at myhost ~]$ one start
[oneadmin at myhost ~]$ opennebula-3.8.1/share/scripts/one status
UP: Found /usr/bin/oned running with PID 30006
UP: Found /usr/bin/mm_sched running with PID 30007
[oneadmin at myhost ~]$ 

I've not yet patched the active script but this shows how it works.

Regards,

Simon


More information about the Users mailing list