3 # Copyright 2023 Koha Development team
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 . /lib/lsb/init-functions
22 # Read configuration variable file if it is present
23 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
25 # include helper functions
26 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
27 . "/usr/share/koha/bin/koha-functions.sh"
29 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
35 local scriptname=$(basename $0)
40 This script lets you manage the ES indexing daemon for your Koha instances.
43 $scriptname [--start|--stop|--restart] [--batch_size N] [--quiet|-q] instancename1 [instancename2...]
44 $scriptname --status instancename1 [instancename2...]
47 --start Start the ES indexing daemon for the specified instances
48 --stop Stop the ES indexing daemon for the specified instances
49 --restart Restart the ES indexing daemon for the specified instances
50 --batch_size N Specify the batch size to commit at a time (default: 10)
51 --status Show the status of the ES indexing for the specified instances
52 --quiet|-q Make the script quiet about non existent instance names
53 (useful for calling from another scripts).
54 --help|-h Display this help message
63 if ! is_es_indexer_running $name; then
65 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
67 DAEMONOPTS="--name=$name-koha-es-indexer \
68 --errlog=/var/log/koha/$name/es-indexer-error.log \
69 --output=/var/log/koha/$name/es-indexer-output.log \
70 --pidfiles=/var/run/koha/$name/ \
71 --verbose=1 --respawn --delay=30 \
72 --user=$name-koha.$name-koha"
74 log_daemon_msg "Starting Koha ES indexing daemon for $name"
76 if daemon $DAEMONOPTS -- $worker_DAEMON --batch_size ${batch_size}; then
82 log_daemon_msg "Error: ES indexing daemon already running for $name"
91 if is_es_indexer_running $name; then
92 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
94 DAEMONOPTS="--name=$name-koha-es-indexer \
95 --errlog=/var/log/koha/$name/es-indexer-error.log \
96 --output=/var/log/koha/$name/es-indexer-output.log \
97 --pidfiles=/var/run/koha/$name/ \
98 --verbose=1 --respawn --delay=30 \
99 --user=$name-koha.$name-koha"
101 log_daemon_msg "Stopping Koha ES indexing daemon for $name"
103 if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then
109 log_daemon_msg "Error: ES indexing daemon not running for $name"
119 if is_es_indexer_running $name; then
120 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
122 DAEMONOPTS="--name=$name-koha-es-indexer \
123 --errlog=/var/log/koha/$name/es-indexer-error.log \
124 --output=/var/log/koha/$name/es-indexer-output.log \
125 --pidfiles=/var/run/koha/$name/ \
126 --verbose=1 --respawn --delay=30 \
127 --user=$name-koha.$name-koha"
129 log_daemon_msg "Restarting Koha ES indexing daemon for $name"
131 if daemon $DAEMONOPTS --restart -- $worker_DAEMON --batch_size ${batch_size}; then
137 log_warning_msg "ES indexing daemon not running for $name."
138 start_es_indexer $name
146 if is_es_indexer_running $name; then
147 log_daemon_msg "ES indexing daemon running for ${name}"
150 log_daemon_msg "ES indexing daemon not running for ${name}"
157 if [ "$op" = "" ]; then
160 die "Error: only one action can be specified."
168 # Read command line parameters
169 while [ $# -gt 0 ]; do
193 die "Error: invalid option switch ($1)" ;;
195 # We expect the remaining stuff are the instance names
201 # Optionally use alternative paths for a dev install
202 adjust_paths_dev_install $1
204 if [ "$DEV_INSTALL" = "" ]; then
205 worker_DAEMON="${KOHA_HOME}/bin/workers/es_indexer_daemon.pl"
207 worker_DAEMON="${KOHA_HOME}/misc/workers/es_indexer_daemon.pl"
210 # PERL5LIB has been read from etc/default
213 if [ $# -gt 0 ]; then
214 # We have at least one instance name
217 if is_instance $name; then
221 start_es_indexer $name
224 stop_es_indexer $name
227 restart_es_indexer $name
230 es_indexer_status $name
234 if [ "$quiet" = "no" ]; then
235 log_daemon_msg "Error: Invalid instance name $name"
242 if [ "$quiet" = "no" ]; then
243 warn "Error: you must provide at least one instance name"