Bug 10624: add 'status' option switch for the packages init script
authorTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 30 Aug 2013 16:17:55 +0000 (13:17 -0300)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 9 Oct 2013 04:53:42 +0000 (04:53 +0000)
This patch makes the init script return the status of the relevant
processes.

To test:
- Apply the patch, build package and install
- Run
 $ service koha-common status

Note: it can be tested just copying the debian/koha-common.init script
to a server running koha-common instances and calling it

 $ ./koha-common.init status

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
debian/koha-common.init

index 38eafcf..1ba591d 100755 (executable)
@@ -70,6 +70,75 @@ do_reload() {
     koha-start-sip $(koha-list --enabled)
 }
 
+#
+# Function that checks zebrasrv is running for the specified instance
+#
+is_zebra_running()
+{
+    local instancename=$1
+
+    if daemon --name="$instancename-koha-zebra" \
+            --user="$instancename-koha.$instancename-koha" \
+            --running ; then
+        return 0
+    else
+        return 1
+    fi
+}
+
+#
+# Function that checks SIP server is running for the specified instance
+#
+is_sip_running()
+{
+    local instancename=$1
+
+    if daemon --name="$instancename-koha-sip" \
+            --pidfiles="/var/run/koha/$instancename" \
+            --user="$instancename-koha.$instancename-koha" \
+            --running ; then
+        return 0
+    else
+        return 1
+    fi
+}
+
+#
+# Function that shows the status of the zebrasrv daemon for
+# enabled instances
+#
+zebra_status()
+{
+    for instance in $(koha-list --enabled); do
+
+        log_daemon_msg "Zebra server running for instace $instance"
+
+        if is_zebra_running $instance ; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+        fi
+    done
+}
+
+#
+# Function that shows the status of the SIP server daemon for
+# enabled instances
+#
+sip_status()
+{
+    for instance in $(koha-list --enabled --sip); do
+
+        log_daemon_msg "SIP server running for instace $instance"
+
+        if is_sip_running $instance ; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+        fi
+    done
+}
+
 case "$1" in
   start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
@@ -108,13 +177,12 @@ case "$1" in
                ;;
        esac
        ;;
-# TODO: Implement this. It should check every daemon is running
-#  status)
-#        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
-#        ;;
+  status)
+        zebra_status
+        sip_status
+        ;;
   *)
-    #echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
-    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
        exit 3
        ;;
 esac