From 3fcb356d3b71c8875c82c314ed0c98d6ba3b9f5b Mon Sep 17 00:00:00 2001
From: Magnus Enger <magnus@libriotech.no>
Date: Mon, 30 Sep 2019 10:03:13 +0200
Subject: [PATCH] Bug 23400 - Add --status to koha-indexer

koha-zebra has a nice, informative --status switch, koha-indexer
does not. This patch adds it.

To test:
- Run "sudo koha-indexer --status kohadev" - you get an error:
  "Error: invalid option switch (--status)"
- Apply this patch
- If you are on e.g. kohadevbox you need to copy koha-indexer to
  where it is actually run from:
  sudo cp debian/scripts/koha-indexer /usr/sbin/koha-indexer
- Run "sudo koha-indexer --status kohadev" again and you should
  get a nice status telling if the indexer is running or not
- Toggle the indexer on and off with koha-indexer --start/--stop
  and verify the status is telling the truth about the state of
  the indexer
- Run "sudo koha-indexer --help" and check there is a description
  of the --status option
- Have a look at debian/docs/koha-indexer.xml and verify there is
  an adequate description of the --status option.
- Run "prove -v xt/verify-debian-docbook.t" to check the structure
  of the man page in DocBook format.

PS: I tried to generate a manpage from the DocBook as described at
https://wiki.koha-community.org/wiki/Testing_man_pages
but the output did not look good for any of our DocBook files.
Not sure why.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 debian/docs/koha-indexer.xml |  9 ++++++++-
 debian/scripts/koha-indexer  | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/debian/docs/koha-indexer.xml b/debian/docs/koha-indexer.xml
index 66e177cdff..b7f76cb3bd 100644
--- a/debian/docs/koha-indexer.xml
+++ b/debian/docs/koha-indexer.xml
@@ -24,7 +24,7 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       <command>koha-indexer</command>
-      <arg choice="req"><option>--start</option>|<option>--stop</option>|<option>--restart</option>|<option>--help</option>|<option>-h</option>|<option>--quiet</option>|<option>-q</option></arg>
+      <arg choice="req"><option>--start</option>|<option>--stop</option>|<option>--restart</option>|<option>--status</option>|<option>--help</option>|<option>-h</option>|<option>--quiet</option>|<option>-q</option></arg>
       <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -55,6 +55,13 @@
     </varlistentry>
 
     <varlistentry>
+      <term><option>--status</option></term>
+      <listitem>
+        <para>Show the status of the indexer for the specified instances.</para>
+      </listitem>
+    </varlistentry>
+
+    <varlistentry>
       <term><option>--quiet|-q</option></term>
       <listitem>
         <para>Make the script quiet about non existent instance names. Useful when calling <command>koha-indexer</command> from another scripts.</para>
diff --git a/debian/scripts/koha-indexer b/debian/scripts/koha-indexer
index 453f358627..65b80a63df 100755
--- a/debian/scripts/koha-indexer
+++ b/debian/scripts/koha-indexer
@@ -47,6 +47,7 @@ $scriptname -h|--help
     --start               Start the indexer daemon for the specified instances
     --stop                Stop the indexer daemon for the specified instances
     --restart             Restart the indexer daemon for the specified instances
+    --status              Show the status of the indexer for the specified instances
     --quiet|-q            Make the script quiet about non existent instance names
                           (useful for calling from another scripts).
     --help|-h             Display this help message
@@ -138,6 +139,19 @@ restart_indexer()
     fi
 }
 
+indexer_status()
+{
+    local name=$1
+
+    if is_indexer_running ${name}; then
+        log_daemon_msg "Indexer running for ${name}"
+        log_end_msg 0
+    else
+        log_daemon_msg "Indexer not running for ${name}"
+        log_end_msg 3
+    fi
+}
+
 set_action()
 {
     if [ "$op" = "" ]; then
@@ -168,6 +182,9 @@ while [ $# -gt 0 ]; do
         --restart)
             set_action "restart"
             shift ;;
+        --status)
+            set_action "status"
+            shift ;;
         -*)
             die "Error: invalid option switch ($1)" ;;
         *)
@@ -221,6 +238,8 @@ if [ $# -gt 0 ]; then
                 "restart")
                     restart_indexer $name
                     ;;
+                "status")
+                    indexer_status $name
             esac
 
         else
-- 
2.11.0