[Koha-patches] [PATCH 21/28] Add scripts to start, stop, restart Zebra, and rebuild its indexes.

Lars Wirzenius lars at catalyst.net.nz
Tue May 25 03:44:20 CEST 2010


---
 debian/koha-common.cron.d         |    9 +++
 debian/koha-common.init           |  121 +++++++++++++++++++++++++++++++++++++
 debian/scripts/koha-create        |    2 +
 debian/scripts/koha-rebuild-zebra |   38 ++++++++++++
 debian/scripts/koha-remove        |    1 +
 debian/scripts/koha-restart-zebra |   38 ++++++++++++
 debian/scripts/koha-restore       |    1 +
 debian/scripts/koha-start-zebra   |   37 +++++++++++
 debian/scripts/koha-stop-zebra    |   37 +++++++++++
 debian/templates/zebra.passwd.in  |    1 +
 10 files changed, 285 insertions(+), 0 deletions(-)
 create mode 100644 debian/koha-common.cron.d
 create mode 100755 debian/koha-common.init
 create mode 100755 debian/scripts/koha-rebuild-zebra
 create mode 100755 debian/scripts/koha-restart-zebra
 create mode 100755 debian/scripts/koha-start-zebra
 create mode 100755 debian/scripts/koha-stop-zebra
 create mode 100644 debian/templates/zebra.passwd.in

diff --git a/debian/koha-common.cron.d b/debian/koha-common.cron.d
new file mode 100644
index 0000000..715d1b0
--- /dev/null
+++ b/debian/koha-common.cron.d
@@ -0,0 +1,9 @@
+# /etc/cron.d/koha-common
+#
+# Call koha-rebuild-zebra for each enabled Koha instance, to make sure the
+# Zebra indexes are up to date.
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+*/5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra $(koha-list --enabled)
diff --git a/debian/koha-common.init b/debian/koha-common.init
new file mode 100755
index 0000000..719a584
--- /dev/null
+++ b/debian/koha-common.init
@@ -0,0 +1,121 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          koha-common
+# Required-Start:    $remote_fs
+# Required-Stop:     $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start Zebra server 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).
+### END INIT INFO
+
+# Author: Lars Wirzenius <lars at catalyst.net.nz>
+
+# Do NOT "set -e"
+
+# 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
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x /usr/sbin/koha-start-zebra ] || exit 0
+
+# Read configuration variable file if it is present
+# [ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+    koha-start-zebra $(koha-list --enabled)
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+    # We stop everything, including disabled ones.
+    koha-stop-zebra $(koha-list) || true
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+    koha-restart-zebra $(koha-list --enabled)
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		*) [ "$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
+	# 'force-reload' alias
+	#
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+	#echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create
index 1db804a..7a7fa45 100755
--- a/debian/scripts/koha-create
+++ b/debian/scripts/koha-create
@@ -165,6 +165,8 @@ generate_config_file zebra-authorities-site.cfg.in \
     "/etc/koha/sites/$name/zebra-authorities.cfg"
 generate_config_file zebra-authorities-dom-site.cfg.in \
     "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
+generate_config_file zebra.passwd.in \
+    "/etc/koha/sites/$name/zebra.passwd"
 
 
 # Upgrade the database schema, just in case the dump was from an old version.
diff --git a/debian/scripts/koha-rebuild-zebra b/debian/scripts/koha-rebuild-zebra
new file mode 100755
index 0000000..7da1066
--- /dev/null
+++ b/debian/scripts/koha-rebuild-zebra
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# koha-rebuild-zebra -- Rebuild the Zebra database for a Koha instance.
+# Copyright 2010  Catalyst IT, Ltd
+# 
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+set -e
+
+
+if [ "$1" = --full ]
+then
+    opts="-r"
+    shift
+else
+    opts="-z"
+fi
+
+
+for name in "$@"
+do
+    sudo -u "$name-koha" \
+    env PERL5LIB=/usr/share/koha/lib \
+        KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
+        /usr/share/koha/bin/migration_tools/rebuild_zebra.pl -b -a $opts
+done
diff --git a/debian/scripts/koha-remove b/debian/scripts/koha-remove
index 728f996..7b4a19e 100755
--- a/debian/scripts/koha-remove
+++ b/debian/scripts/koha-remove
@@ -35,6 +35,7 @@ eof
     rm "/etc/koha/sites/$name/zebra-biblios.cfg"
     rm "/etc/koha/sites/$name/zebra-authorities.cfg"
     rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
+    rm "/etc/koha/sites/$name/zebra.passwd"
     rmdir "/etc/koha/sites/$name"
     rm -r "/var/lock/koha/$name"
     rm -r "/var/log/koha/$name"
diff --git a/debian/scripts/koha-restart-zebra b/debian/scripts/koha-restart-zebra
new file mode 100755
index 0000000..6b5c0ca
--- /dev/null
+++ b/debian/scripts/koha-restart-zebra
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# koha-restart-zebra -- Restart Zebra for named Koha instandes
+# Copyright 2010  Catalyst IT, Ltd
+# 
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    echo "Restarting Zebra server for $name"
+    daemon \
+        --name="$name-koha-zebra" \
+        --errlog="/var/log/koha/$name/zebra-error.log" \
+        --stdout="/var/log/koha/$name/zebra.log" \
+        --output="/var/log/koha/$name/zebra-output.log" \
+        --verbose=1 \
+        --respawn \
+        --delay=30 \
+        --user="$name-koha.$name-koha" \
+        --restart \
+        -- \
+        zebrasrv \
+        -v none,fatal,warn \
+        -f "/etc/koha/sites/$name/koha-conf.xml"
+done
diff --git a/debian/scripts/koha-restore b/debian/scripts/koha-restore
index d6e324e..f4750e4 100755
--- a/debian/scripts/koha-restore
+++ b/debian/scripts/koha-restore
@@ -74,6 +74,7 @@ CREATE USER '$mysqluser' IDENTIFIED BY '$mysqlpwd';
 GRANT ALL PRIVILEGES ON $mysqldb.* TO '$mysqluser';
 FLUSH PRIVILEGES;
 eof
+koha-rebuild-zebra --full "$name"
 
 
 # Restart Apache.
diff --git a/debian/scripts/koha-start-zebra b/debian/scripts/koha-start-zebra
new file mode 100755
index 0000000..52c6041
--- /dev/null
+++ b/debian/scripts/koha-start-zebra
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# koha-start-zebra -- Start Zebra for named Koha instandes
+# Copyright 2010  Catalyst IT, Ltd
+# 
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    echo "Starting Zebra server for $name"
+    daemon \
+        --name="$name-koha-zebra" \
+        --errlog="/var/log/koha/$name/zebra-error.log" \
+        --stdout="/var/log/koha/$name/zebra.log" \
+        --output="/var/log/koha/$name/zebra-output.log" \
+        --verbose=1 \
+        --respawn \
+        --delay=30 \
+        --user="$name-koha.$name-koha" \
+        -- \
+        zebrasrv \
+        -v none,fatal,warn \
+        -f "/etc/koha/sites/$name/koha-conf.xml"
+done
diff --git a/debian/scripts/koha-stop-zebra b/debian/scripts/koha-stop-zebra
new file mode 100755
index 0000000..3ddd697
--- /dev/null
+++ b/debian/scripts/koha-stop-zebra
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# koha-stop-zebra -- Stop Zebra for named Koha instandes
+# Copyright 2010  Catalyst IT, Ltd
+# 
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    echo "Stopping Zebra server for $name"
+    daemon \
+        --name="$name-koha-zebra" \
+        --errlog="/var/log/koha/$name/zebra-error.log" \
+        --stdout="/var/log/koha/$name/zebra.log" \
+        --output="/var/log/koha/$name/zebra-output.log" \
+        --verbose=1 \
+        --respawn \
+        --delay=30 \
+        --user="$name-koha.$name-koha" \
+        --stop \
+        -- \
+        zebrasrv \
+        -f "/etc/koha/sites/$name/koha-conf.xml"
+done
diff --git a/debian/templates/zebra.passwd.in b/debian/templates/zebra.passwd.in
new file mode 100644
index 0000000..b21a10c
--- /dev/null
+++ b/debian/templates/zebra.passwd.in
@@ -0,0 +1 @@
+kohauser:__ZEBRA_PASS__
-- 
1.7.1




More information about the Koha-patches mailing list