ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / debian / koha-common.init
index 9a285a3..99df08b 100755 (executable)
@@ -1,14 +1,16 @@
 #! /bin/sh
 ### BEGIN INIT INFO
 # Provides:          koha-common
-# Required-Start:    $remote_fs
+# Required-Start:    $remote_fs memcached
 # Required-Stop:     $remote_fs
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
-# Short-Description: Start Zebra server for each Koha instance
+# Short-Description: Start required services for each Koha instance
 # Description:       For each enabled Koha instance on this host,
-#                    as listed by "koha-list --enabled", start a Zebra
-#                    server (using koha-start-zebra).
+#                    if enabled, start:
+#                      - a Zebra server (using koha-zebra)
+#                      - a Plack server (using koha-plack)
+#                      - a SIP server   (using koha-sip)
 ### END INIT INFO
 
 # Author: Lars Wirzenius <lars@catalyst.net.nz>
 # PATH should only include /usr/* if it runs after the mountnfs.sh script
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="Koha ILS"
-NAME=daemonexecutablename
-DAEMON=/usr/sbin/$NAME
-DAEMON_ARGS="--options args"
-PIDFILE=/var/run/$NAME.pid
+NAME="koha-common"
 SCRIPTNAME=/etc/init.d/$NAME
 
 # Exit if the package is not installed
-[ -x /usr/sbin/koha-start-zebra ] || exit 0
+[ -x /usr/sbin/koha-zebra ] || exit 0
 
 # Read configuration variable file if it is present
-# [ -r /etc/default/$NAME ] && . /etc/default/$NAME
+if [ -r /etc/default/$NAME ]; then
+    # Debian / Ubuntu
+    . /etc/default/$NAME
+elif [ -r /etc/sysconfig/$NAME ]; then
+    # RedHat / SuSE
+    . /etc/sysconfig/$NAME
+fi
 
 # Load the VERBOSE setting and other rcS variables
 . /lib/init/vars.sh
@@ -37,6 +42,14 @@ SCRIPTNAME=/etc/init.d/$NAME
 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 . /lib/lsb/init-functions
 
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+    exit 1
+fi
+
 #
 # Function that starts the daemon/service
 #
@@ -44,8 +57,13 @@ do_start()
 {
     # We insure all required directories exist, including disabled ones.
     koha-create-dirs $(koha-list)
-    koha-start-zebra $(koha-list --enabled)
-    koha-start-sip $(koha-list --enabled)
+    koha-zebra --start $(koha-list --enabled)
+    koha-sip   --start $(koha-list --enabled --sip)
+    koha-plack --start $(koha-list --enabled --plack)
+
+    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
+        koha-indexer --start --quiet $(koha-list --enabled)
+    fi
 }
 
 #
@@ -54,17 +72,80 @@ do_start()
 do_stop()
 {
     # We stop everything, including disabled ones.
-    koha-stop-zebra $(koha-list) || true
-    koha-stop-sip $(koha-list) || true
+    koha-zebra --stop $(koha-list) || true
+    koha-sip   --stop $(koha-list --sip)
+    koha-plack --stop --quiet $(koha-list --enabled --plack)
+
+    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
+        koha-indexer --stop --quiet $(koha-list --enabled)
+    fi
 }
 
 #
 # Function that sends a SIGHUP to the daemon/service
 #
 do_reload() {
-    koha-restart-zebra $(koha-list --enabled)
-    koha-stop-sip $(koha-list) || true
-    koha-start-sip $(koha-list --enabled)
+    koha-zebra --restart $(koha-list --enabled)
+    koha-sip   --restart $(koha-list --enabled --sip)
+    koha-plack --restart --quiet $(koha-list --enabled --plack)
+
+    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
+        koha-indexer --restart --quiet $(koha-list --enabled)
+    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 instance $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 instance $instance"
+
+        if is_sip_running $instance ; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+        fi
+    done
+}
+
+#
+# Function that shows the status of the Plack server daemon for
+# enabled instances
+#
+plack_status()
+{
+    for instance in $(koha-list --enabled --plack); do
+
+        log_daemon_msg "Plack server running for instance ${instance}"
+
+        if is_plack_running $instance ; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+        fi
+    done
 }
 
 case "$1" in
@@ -84,18 +165,6 @@ case "$1" in
                *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
-#  status)
-#       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
-#       ;;
-  #reload|force-reload)
-       #
-       # If do_reload() is not implemented then leave this commented out
-       # and leave 'force-reload' as an alias for 'restart'.
-       #
-       #log_daemon_msg "Reloading $DESC" "$NAME"
-       #do_reload
-       #log_end_msg $?
-       #;;
   restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
@@ -117,9 +186,13 @@ case "$1" in
                ;;
        esac
        ;;
+  status)
+        zebra_status
+        sip_status
+        plack_status
+        ;;
   *)
-       echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
-       #echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
        exit 3
        ;;
 esac