3 # Copyright 2020 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 worker daemon for your Koha instances.
43 $scriptname [--start|--stop|--restart] [--queue queue_name] [--quiet|-q] instancename1 [instancename2...]
44 $scriptname --status instancename1 [instancename2...]
47 --start Start the worker daemon for the specified instances
48 --stop Stop the worker daemon for the specified instances
49 --restart Restart the worker daemon for the specified instances
50 --queue Specify the queue/worker to restart - 'default' is used if not specified
51 current queues are: default, long_tasks
52 --status Show the status of the worker for the specified instances
53 --quiet|-q Make the script quiet about non existent instance names
54 (useful for calling from another scripts).
55 --help|-h Display this help message
65 if ! is_worker_running $name $queue; then
67 worker_name=`get_worker_name $name $queue`
69 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
71 DAEMONOPTS="--name=${worker_name} \
72 --errlog=/var/log/koha/$name/worker-error.log \
73 --stdout=/var/log/koha/$name/worker.log \
74 --output=/var/log/koha/$name/worker-output.log \
75 --pidfiles=/var/run/koha/$name/ \
76 --verbose=1 --respawn --delay=30 \
77 --user=$name-koha.$name-koha"
79 log_daemon_msg "Starting Koha worker daemon for $name ($queue)"
81 if daemon $DAEMONOPTS -- $worker_DAEMON --queue ${queue}; then
87 log_daemon_msg "Error: worker already running for $name ($queue)"
97 if is_worker_running $name $queue; then
98 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
100 worker_name=`get_worker_name $name $queue`
102 DAEMONOPTS="--name=${worker_name} \
103 --errlog=/var/log/koha/$name/worker-error.log \
104 --stdout=/var/log/koha/$name/worker.log \
105 --output=/var/log/koha/$name/worker-output.log \
106 --pidfiles=/var/run/koha/$name/ \
107 --verbose=1 --respawn --delay=30 \
108 --user=$name-koha.$name-koha"
110 log_daemon_msg "Stopping Koha worker daemon for $name ($queue)"
112 if daemon $DAEMONOPTS --stop -- $worker_DAEMON --queue ${queue}; then
118 log_daemon_msg "Error: worker not running for $name ($queue)"
128 if is_worker_running $name $queue; then
129 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
131 worker_name=`get_worker_name $name $queue`
133 DAEMONOPTS="--name=${worker_name} \
134 --errlog=/var/log/koha/$name/worker-error.log \
135 --stdout=/var/log/koha/$name/worker.log \
136 --output=/var/log/koha/$name/worker-output.log \
137 --pidfiles=/var/run/koha/$name/ \
138 --verbose=1 --respawn --delay=30 \
139 --user=$name-koha.$name-koha"
141 log_daemon_msg "Restarting Koha worker daemon for $name ($queue)"
143 if daemon $DAEMONOPTS --restart -- $worker_DAEMON --queue ${queue}; then
149 log_warning_msg "Worker not running for $name ($queue)."
150 start_worker $name $queue
159 if is_worker_running ${name} ${queue}; then
160 log_daemon_msg "worker running for ${name} ($queue)"
163 log_daemon_msg "worker not running for ${name} ($queue)"
170 if [ "$op" = "" ]; then
173 die "Error: only one action can be specified."
181 # Read command line parameters
182 while [ $# -gt 0 ]; do
206 die "Error: invalid option switch ($1)" ;;
208 # We expect the remaining stuff are the instance names
214 # Optionally use alternative paths for a dev install
215 adjust_paths_dev_install $1
217 if [ "$DEV_INSTALL" = "" ]; then
218 worker_DAEMON="${KOHA_HOME}/bin/background_jobs_worker.pl"
220 worker_DAEMON="${KOHA_HOME}/misc/background_jobs_worker.pl"
223 # PERL5LIB has been read from etc/default
226 if [ $# -gt 0 ]; then
227 # We have at least one instance name
230 if is_instance $name; then
234 start_worker $name $queue
237 stop_worker $name $queue
240 restart_worker $name $queue
243 worker_status $name $queue
247 if [ "$quiet" = "no" ]; then
248 log_daemon_msg "Error: Invalid instance name $name"
255 if [ "$quiet" = "no" ]; then
256 warn "Error: you must provide at least one instance name"