Merge branch 'bug_10287' into 3.14-master
[koha.git] / misc / bin / koha-zebra-ctl.sh
index 5c0422a..397eb19 100755 (executable)
@@ -1,7 +1,33 @@
 #!/bin/bash
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+### BEGIN INIT INFO
+# Provides:          koha-zebra-daemon
+# Required-Start:    $syslog $remote_fs
+# Required-Stop:     $syslog $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Zebra server daemon for Koha indexing
+### END INIT INFO
+
 USER=__KOHA_USER__
 GROUP=__KOHA_GROUP__
-NAME=koha-zebra-ctl
+DBNAME=__DB_NAME__
+NAME=koha-zebra-ctl.$DBNAME
 LOGDIR=__LOG_DIR__
 ERRLOG=$LOGDIR/koha-zebradaemon.err
 STDOUT=$LOGDIR/koha-zebradaemon.log
@@ -10,10 +36,16 @@ KOHA_CONF=__KOHA_CONF_DIR__/koha-conf.xml
 RUNDIR=__ZEBRA_RUN_DIR__
 LOCKDIR=__ZEBRA_LOCK_DIR__
 # you may need to change this depending on where zebrasrv is installed
-ZEBRASRV=/usr/bin/zebrasrv
+ZEBRASRV=__PATH_TO_ZEBRA__/zebrasrv
+ZEBRAOPTIONS="-v none,fatal,warn"
 
 test -f $ZEBRASRV || exit 0
 
+OTHERUSER=''
+if [[ $EUID -eq 0 ]]; then
+    OTHERUSER="--user=$USER.$GROUP"
+fi
+
 case "$1" in
     start)
       echo "Starting Zebra Server"
@@ -24,25 +56,29 @@ case "$1" in
       if [[ ! -d $RUNDIR ]]; then
         umask 022
         mkdir -p $RUNDIR
-        chown $USER:$GROUP $RUNDIR
+        if [[ $EUID -eq 0 ]]; then
+            chown $USER:$GROUP $RUNDIR
+        fi
       fi
       if [[ ! -d $LOCKDIR ]]; then
         umask 022
         mkdir -p $LOCKDIR
         mkdir -p $LOCKDIR/biblios
         mkdir -p $LOCKDIR/authorities
-        chown -R $USER:$GROUP $LOCKDIR
+        if [[ $EUID -eq 0 ]]; then
+            chown -R $USER:$GROUP $LOCKDIR
+        fi
       fi
 
-      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 --user=$USER.$GROUP -- $ZEBRASRV -f $KOHA_CONF 
+      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER -- $ZEBRASRV $ZEBRAOPTIONS -f $KOHA_CONF 
       ;;
     stop)
       echo "Stopping Zebra Server"
-      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 --user=$USER.$GROUP --stop -- $ZEBRASRV -f $KOHA_CONF 
+      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --stop -- $ZEBRASRV -f $KOHA_CONF 
       ;;
     restart)
       echo "Restarting the Zebra Server"
-      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 --user=$USER.$GROUP --restart -- $ZEBRASRV -f $KOHA_CONF 
+      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --restart -- $ZEBRASRV -f $KOHA_CONF 
       ;;
     *)
       echo "Usage: /etc/init.d/$NAME {start|stop|restart}"