|
Lines 15-22
Link Here
|
| 15 |
# You should have received a copy of the GNU General Public License |
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/>. |
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
17 |
|
| 18 |
set -e |
|
|
| 19 |
|
| 20 |
. /lib/lsb/init-functions |
18 |
. /lib/lsb/init-functions |
| 21 |
|
19 |
|
| 22 |
# Read configuration variable file if it is present |
20 |
# Read configuration variable file if it is present |
|
Lines 40-54
$scriptname
Link Here
|
| 40 |
This script lets you manage the worker daemon for your Koha instances. |
38 |
This script lets you manage the worker daemon for your Koha instances. |
| 41 |
|
39 |
|
| 42 |
Usage: |
40 |
Usage: |
| 43 |
$scriptname [--start|--stop|--restart] [--queue queue_name] [--quiet|-q] instancename1 [instancename2...] |
41 |
$scriptname [--start|--stop|--restart] [--queue queue_name|--all-queues] [--quiet|-q] instancename1 [instancename2...] |
| 44 |
$scriptname --status instancename1 [instancename2...] |
42 |
$scriptname --status instancename1 [instancename2...] |
| 45 |
$scriptname -h|--help |
43 |
$scriptname -h|--help |
| 46 |
|
44 |
|
| 47 |
--start Start the worker daemon for the specified instances |
45 |
--start Start the worker daemon for the specified instances |
| 48 |
--stop Stop the worker daemon for the specified instances |
46 |
--stop Stop the worker daemon for the specified instances |
| 49 |
--restart Restart the worker daemon for the specified instances |
47 |
--restart Restart the worker daemon for the specified instances |
| 50 |
--queue Specify the queue/worker to restart - 'default' is used if not specified |
48 |
--queue Specify the queue/worker to perform the action on - 'default' is |
|
|
49 |
used if not specified (unless --all-queues is passed) |
| 51 |
current queues are: default, long_tasks |
50 |
current queues are: default, long_tasks |
|
|
51 |
--all-queues Perform the action on all defined queues |
| 52 |
--status Show the status of the worker for the specified instances |
52 |
--status Show the status of the worker for the specified instances |
| 53 |
--quiet|-q Make the script quiet about non existent instance names |
53 |
--quiet|-q Make the script quiet about non existent instance names |
| 54 |
(useful for calling from another scripts). |
54 |
(useful for calling from another scripts). |
|
Lines 63-168
EOF
Link Here
|
| 63 |
start_worker() |
63 |
start_worker() |
| 64 |
{ |
64 |
{ |
| 65 |
local name=$1 |
65 |
local name=$1 |
| 66 |
local queue=$2 |
66 |
local queues=$2 |
| 67 |
|
67 |
|
| 68 |
if ! is_worker_running $name $queue; then |
68 |
local error_count=0 |
| 69 |
|
69 |
|
| 70 |
worker_name=`get_worker_name $name $queue` |
70 |
for queue in $queues; do |
|
|
71 |
if ! is_worker_running "$name" "$queue"; then |
| 71 |
|
72 |
|
| 72 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
73 |
worker_name=$(get_worker_name "$name" "$queue") |
|
|
74 |
export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" |
| 73 |
|
75 |
|
| 74 |
DAEMONOPTS="--name=${worker_name} \ |
76 |
DAEMONOPTS="--name=${worker_name} \ |
| 75 |
--errlog=/var/log/koha/$name/worker-error.log \ |
77 |
--errlog=/var/log/koha/${name}/worker-error.log \ |
| 76 |
--output=/var/log/koha/$name/worker-output.log \ |
78 |
--output=/var/log/koha/${name}/worker-output.log \ |
| 77 |
--pidfiles=/var/run/koha/$name/ \ |
79 |
--pidfiles=/var/run/koha/${name}/ \ |
| 78 |
--verbose=1 --respawn --delay=30 \ |
80 |
--verbose=1 --respawn --delay=30 \ |
| 79 |
--user=$name-koha.$name-koha" |
81 |
--user=${name}-koha.${name}-koha" |
| 80 |
|
82 |
|
| 81 |
log_daemon_msg "Starting Koha worker daemon for $name ($queue)" |
83 |
echo "Starting Koha worker daemon for ${name} (${queue})" |
| 82 |
|
84 |
|
| 83 |
if daemon $DAEMONOPTS -- $worker_DAEMON --queue ${queue}; then |
85 |
if ! daemon $DAEMONOPTS -- "$worker_DAEMON" --queue "$queue"; then |
| 84 |
log_end_msg 0 |
86 |
((error_count++)) |
|
|
87 |
fi |
| 85 |
else |
88 |
else |
| 86 |
log_end_msg 1 |
89 |
echo "Error: worker already running for ${name} (${queue})" |
|
|
90 |
((error_count++)) |
| 87 |
fi |
91 |
fi |
| 88 |
else |
92 |
done |
| 89 |
log_daemon_msg "Error: worker already running for $name ($queue)" |
93 |
|
| 90 |
log_end_msg 1 |
94 |
log_end_msg $error_count |
| 91 |
fi |
|
|
| 92 |
} |
95 |
} |
| 93 |
|
96 |
|
| 94 |
stop_worker() |
97 |
stop_worker() |
| 95 |
{ |
98 |
{ |
| 96 |
local name=$1 |
99 |
local name=$1 |
| 97 |
local queue=$2 |
100 |
local queues=$2 |
| 98 |
|
101 |
|
| 99 |
if is_worker_running $name $queue; then |
102 |
local error_count=0 |
| 100 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
|
|
| 101 |
|
103 |
|
| 102 |
worker_name=`get_worker_name $name $queue` |
104 |
for queue in $queues; do |
|
|
105 |
if is_worker_running "$name" "$queue"; then |
| 106 |
export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" |
| 103 |
|
107 |
|
| 104 |
DAEMONOPTS="--name=${worker_name} \ |
108 |
worker_name=$(get_worker_name "$name" "$queue") |
| 105 |
--errlog=/var/log/koha/$name/worker-error.log \ |
|
|
| 106 |
--output=/var/log/koha/$name/worker-output.log \ |
| 107 |
--pidfiles=/var/run/koha/$name/ \ |
| 108 |
--verbose=1 --respawn --delay=30 \ |
| 109 |
--user=$name-koha.$name-koha" |
| 110 |
|
109 |
|
| 111 |
log_daemon_msg "Stopping Koha worker daemon for $name ($queue)" |
110 |
DAEMONOPTS="--name=${worker_name} \ |
|
|
111 |
--errlog=/var/log/koha/${name}/worker-error.log \ |
| 112 |
--output=/var/log/koha/${name}/worker-output.log \ |
| 113 |
--pidfiles=/var/run/koha/${name}/ \ |
| 114 |
--verbose=1 --respawn --delay=30 \ |
| 115 |
--user=${name}-koha.${name}-koha" |
| 112 |
|
116 |
|
| 113 |
if daemon $DAEMONOPTS --stop -- $worker_DAEMON --queue ${queue}; then |
117 |
echo "Stopping Koha worker daemon for ${name} (${queue})" |
| 114 |
log_end_msg 0 |
118 |
|
|
|
119 |
if ! daemon $DAEMONOPTS --stop -- "$worker_DAEMON" --queue "$queue"; then |
| 120 |
((error_count++)) |
| 121 |
fi |
| 115 |
else |
122 |
else |
| 116 |
log_end_msg 1 |
123 |
echo "Error: worker not running for ${name} (${queue})" |
|
|
124 |
((error_count++)) |
| 117 |
fi |
125 |
fi |
| 118 |
else |
126 |
done |
| 119 |
log_daemon_msg "Error: worker not running for $name ($queue)" |
127 |
|
| 120 |
log_end_msg 1 |
128 |
log_end_msg $error_count |
| 121 |
fi |
|
|
| 122 |
} |
129 |
} |
| 123 |
|
130 |
|
| 124 |
restart_worker() |
131 |
restart_worker() |
| 125 |
{ |
132 |
{ |
| 126 |
local name=$1 |
133 |
local name=$1 |
| 127 |
local queue=$2 |
134 |
local queues=$2 |
| 128 |
|
135 |
|
| 129 |
if is_worker_running $name $queue; then |
136 |
local error_count=0 |
| 130 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
|
|
| 131 |
|
137 |
|
| 132 |
worker_name=`get_worker_name $name $queue` |
138 |
for queue in $queues; do |
|
|
139 |
if is_worker_running "$name" "$queue"; then |
| 140 |
export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" |
| 133 |
|
141 |
|
| 134 |
DAEMONOPTS="--name=${worker_name} \ |
142 |
worker_name=$(get_worker_name "$name" "$queue") |
| 135 |
--errlog=/var/log/koha/$name/worker-error.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" |
| 140 |
|
143 |
|
| 141 |
log_daemon_msg "Restarting Koha worker daemon for $name ($queue)" |
144 |
DAEMONOPTS="--name=${worker_name} \ |
|
|
145 |
--errlog=/var/log/koha/${name}/worker-error.log \ |
| 146 |
--output=/var/log/koha/${name}/worker-output.log \ |
| 147 |
--pidfiles=/var/run/koha/${name}/ \ |
| 148 |
--verbose=1 --respawn --delay=30 \ |
| 149 |
--user=${name}-koha.${name}-koha" |
| 142 |
|
150 |
|
| 143 |
if daemon $DAEMONOPTS --restart -- $worker_DAEMON --queue ${queue}; then |
151 |
echo "Restarting Koha worker daemon for ${name} (${queue})" |
| 144 |
log_end_msg 0 |
152 |
|
|
|
153 |
if ! daemon $DAEMONOPTS --restart -- "$worker_DAEMON" --queue "$queue"; then |
| 154 |
((error_count++)) |
| 155 |
fi |
| 145 |
else |
156 |
else |
| 146 |
log_end_msg 1 |
157 |
echo "Worker not running for ${name} (${queue})." |
|
|
158 |
start_worker $name $queue |
| 147 |
fi |
159 |
fi |
| 148 |
else |
160 |
done |
| 149 |
log_warning_msg "Worker not running for $name ($queue)." |
161 |
|
| 150 |
start_worker $name $queue |
162 |
log_end_msg $error_count |
| 151 |
fi |
|
|
| 152 |
} |
163 |
} |
| 153 |
|
164 |
|
| 154 |
worker_status() |
165 |
worker_status() |
| 155 |
{ |
166 |
{ |
| 156 |
local name=$1 |
167 |
local name=$1 |
| 157 |
local queue=$2 |
168 |
local queues=$2 |
| 158 |
|
169 |
|
| 159 |
if is_worker_running ${name} ${queue}; then |
170 |
for queue in $queues; do |
| 160 |
log_daemon_msg "worker running for ${name} ($queue)" |
171 |
if is_worker_running "$name" "$queue"; then |
| 161 |
log_end_msg 0 |
172 |
log_daemon_msg "worker running for ${name} (${queue})" |
| 162 |
else |
173 |
log_end_msg 0 |
| 163 |
log_daemon_msg "worker not running for ${name} ($queue)" |
174 |
else |
| 164 |
log_end_msg 3 |
175 |
log_daemon_msg "worker not running for ${name} (${queue})" |
| 165 |
fi |
176 |
log_end_msg 3 |
|
|
177 |
fi |
| 178 |
done |
| 166 |
} |
179 |
} |
| 167 |
|
180 |
|
| 168 |
set_action() |
181 |
set_action() |
|
Lines 177-182
set_action()
Link Here
|
| 177 |
op="" |
190 |
op="" |
| 178 |
queue="default" |
191 |
queue="default" |
| 179 |
quiet="no" |
192 |
quiet="no" |
|
|
193 |
all_queues="no" |
| 180 |
|
194 |
|
| 181 |
# Read command line parameters |
195 |
# Read command line parameters |
| 182 |
while [ $# -gt 0 ]; do |
196 |
while [ $# -gt 0 ]; do |
|
Lines 202-207
while [ $# -gt 0 ]; do
Link Here
|
| 202 |
--queue) |
216 |
--queue) |
| 203 |
queue="$2" |
217 |
queue="$2" |
| 204 |
shift 2 ;; |
218 |
shift 2 ;; |
|
|
219 |
--all-queues) |
| 220 |
all_queues="yes"; |
| 221 |
shift ;; |
| 205 |
-*) |
222 |
-*) |
| 206 |
die "Error: invalid option switch ($1)" ;; |
223 |
die "Error: invalid option switch ($1)" ;; |
| 207 |
*) |
224 |
*) |
|
Lines 212-218
while [ $# -gt 0 ]; do
Link Here
|
| 212 |
done |
229 |
done |
| 213 |
|
230 |
|
| 214 |
# Optionally use alternative paths for a dev install |
231 |
# Optionally use alternative paths for a dev install |
| 215 |
adjust_paths_dev_install $1 |
232 |
adjust_paths_dev_install "$1" |
| 216 |
|
233 |
|
| 217 |
if [ "$DEV_INSTALL" = "" ]; then |
234 |
if [ "$DEV_INSTALL" = "" ]; then |
| 218 |
worker_DAEMON="${KOHA_HOME}/bin/workers/background_jobs_worker.pl" |
235 |
worker_DAEMON="${KOHA_HOME}/bin/workers/background_jobs_worker.pl" |
|
Lines 229-246
if [ $# -gt 0 ]; then
Link Here
|
| 229 |
|
246 |
|
| 230 |
if is_instance $name; then |
247 |
if is_instance $name; then |
| 231 |
|
248 |
|
|
|
249 |
if [ "$all_queues" = "yes" ]; then |
| 250 |
queues=$(get_worker_queues | xargs) |
| 251 |
else |
| 252 |
queues=$queue |
| 253 |
fi |
| 254 |
|
| 232 |
case $op in |
255 |
case $op in |
| 233 |
"start") |
256 |
"start") |
| 234 |
start_worker $name $queue |
257 |
start_worker "$name" "$queues" |
| 235 |
;; |
258 |
;; |
| 236 |
"stop") |
259 |
"stop") |
| 237 |
stop_worker $name $queue |
260 |
stop_worker "$name" "$queues" |
| 238 |
;; |
261 |
;; |
| 239 |
"restart") |
262 |
"restart") |
| 240 |
restart_worker $name $queue |
263 |
restart_worker "$name" "$queues" |
| 241 |
;; |
264 |
;; |
| 242 |
"status") |
265 |
"status") |
| 243 |
worker_status $name $queue |
266 |
worker_status "$name" "$queues" |
| 244 |
esac |
267 |
esac |
| 245 |
|
268 |
|
| 246 |
else |
269 |
else |
| 247 |
- |
|
|