|
Lines 40-46
$scriptname
Link Here
|
| 40 |
This script lets you manage the worker daemon for your Koha instances. |
40 |
This script lets you manage the worker daemon for your Koha instances. |
| 41 |
|
41 |
|
| 42 |
Usage: |
42 |
Usage: |
| 43 |
$scriptname [--start|--stop|--restart] [--queue queue_name] [--quiet|-q] instancename1 [instancename2...] |
43 |
$scriptname [--start|--stop|--restart] [--queue queue_name] [--type job_type] [--not-type job_type] [--quiet|-q] instancename1 [instancename2...] |
| 44 |
$scriptname --status instancename1 [instancename2...] |
44 |
$scriptname --status instancename1 [instancename2...] |
| 45 |
$scriptname -h|--help |
45 |
$scriptname -h|--help |
| 46 |
|
46 |
|
|
Lines 49-54
$scriptname -h|--help
Link Here
|
| 49 |
--restart Restart 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 |
50 |
--queue Specify the queue/worker to restart - 'default' is used if not specified |
| 51 |
current queues are: default, long_tasks |
51 |
current queues are: default, long_tasks |
|
|
52 |
--type Specify the job type for this worker to process |
| 53 |
--not-type Specify the job type for this worker to skip processing |
| 52 |
--status Show the status of the worker for the specified instances |
54 |
--status Show the status of the worker for the specified instances |
| 53 |
--quiet|-q Make the script quiet about non existent instance names |
55 |
--quiet|-q Make the script quiet about non existent instance names |
| 54 |
(useful for calling from another scripts). |
56 |
(useful for calling from another scripts). |
|
Lines 64-73
start_worker()
Link Here
|
| 64 |
{ |
66 |
{ |
| 65 |
local name=$1 |
67 |
local name=$1 |
| 66 |
local queue=$2 |
68 |
local queue=$2 |
|
|
69 |
local job_type=$3 |
| 70 |
local not_job_type=$4 |
| 67 |
|
71 |
|
| 68 |
if ! is_worker_running $name $queue; then |
72 |
if ! is_worker_running $name $queue $job_type $not_job_type; then |
| 69 |
|
73 |
|
| 70 |
worker_name=`get_worker_name $name $queue` |
74 |
worker_name=`get_worker_name $name $queue $job_type $notjob__type` |
| 71 |
|
75 |
|
| 72 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
76 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
| 73 |
|
77 |
|
|
Lines 78-92
start_worker()
Link Here
|
| 78 |
--verbose=1 --respawn --delay=30 \ |
82 |
--verbose=1 --respawn --delay=30 \ |
| 79 |
--user=$name-koha.$name-koha" |
83 |
--user=$name-koha.$name-koha" |
| 80 |
|
84 |
|
| 81 |
log_daemon_msg "Starting Koha worker daemon for $name ($queue)" |
85 |
local job_limits="" |
|
|
86 |
if $job_type; then |
| 87 |
job_limits="--job-type $job_type" |
| 88 |
elif $not_job_type; then |
| 89 |
job_limits="--not-job-type $not_job_type" |
| 90 |
fi |
| 91 |
|
| 92 |
log_daemon_msg "Starting Koha worker daemon for $name --queue $queue $job_limits" |
| 82 |
|
93 |
|
| 83 |
if daemon $DAEMONOPTS -- $worker_DAEMON --queue ${queue}; then |
94 |
if daemon $DAEMONOPTS -- $worker_DAEMON --queue ${queue} $job_limits; then |
| 84 |
log_end_msg 0 |
95 |
log_end_msg 0 |
| 85 |
else |
96 |
else |
| 86 |
log_end_msg 1 |
97 |
log_end_msg 1 |
| 87 |
fi |
98 |
fi |
| 88 |
else |
99 |
else |
| 89 |
log_daemon_msg "Error: worker already running for $name ($queue)" |
100 |
log_daemon_msg "Error: worker already running for --queue $queue $job_limits" |
| 90 |
log_end_msg 1 |
101 |
log_end_msg 1 |
| 91 |
fi |
102 |
fi |
| 92 |
} |
103 |
} |
|
Lines 95-100
stop_worker()
Link Here
|
| 95 |
{ |
106 |
{ |
| 96 |
local name=$1 |
107 |
local name=$1 |
| 97 |
local queue=$2 |
108 |
local queue=$2 |
|
|
109 |
local job_type=$3 |
| 110 |
local not_job_type=$4 |
| 98 |
|
111 |
|
| 99 |
if is_worker_running $name $queue; then |
112 |
if is_worker_running $name $queue; then |
| 100 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
113 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
|
Lines 108-122
stop_worker()
Link Here
|
| 108 |
--verbose=1 --respawn --delay=30 \ |
121 |
--verbose=1 --respawn --delay=30 \ |
| 109 |
--user=$name-koha.$name-koha" |
122 |
--user=$name-koha.$name-koha" |
| 110 |
|
123 |
|
| 111 |
log_daemon_msg "Stopping Koha worker daemon for $name ($queue)" |
124 |
local job_limits="" |
|
|
125 |
if $job_type; then |
| 126 |
job_limits="--job-type $job_type" |
| 127 |
elif $not_job_type; then |
| 128 |
job_limits="--not-job-type $not_job_type" |
| 129 |
fi |
| 130 |
|
| 131 |
log_daemon_msg "Stopping Koha worker daemon for --queue $queue $job_limits" |
| 112 |
|
132 |
|
| 113 |
if daemon $DAEMONOPTS --stop -- $worker_DAEMON --queue ${queue}; then |
133 |
if daemon $DAEMONOPTS --stop -- $worker_DAEMON --queue ${queue} $job_limits; then |
| 114 |
log_end_msg 0 |
134 |
log_end_msg 0 |
| 115 |
else |
135 |
else |
| 116 |
log_end_msg 1 |
136 |
log_end_msg 1 |
| 117 |
fi |
137 |
fi |
| 118 |
else |
138 |
else |
| 119 |
log_daemon_msg "Error: worker not running for $name ($queue)" |
139 |
log_daemon_msg "Error: worker not running for --queue $queue $job_limits" |
| 120 |
log_end_msg 1 |
140 |
log_end_msg 1 |
| 121 |
fi |
141 |
fi |
| 122 |
} |
142 |
} |
|
Lines 125-130
restart_worker()
Link Here
|
| 125 |
{ |
145 |
{ |
| 126 |
local name=$1 |
146 |
local name=$1 |
| 127 |
local queue=$2 |
147 |
local queue=$2 |
|
|
148 |
local job_type=$3 |
| 149 |
local not_job_type=$4 |
| 128 |
|
150 |
|
| 129 |
if is_worker_running $name $queue; then |
151 |
if is_worker_running $name $queue; then |
| 130 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
152 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
|
Lines 138-152
restart_worker()
Link Here
|
| 138 |
--verbose=1 --respawn --delay=30 \ |
160 |
--verbose=1 --respawn --delay=30 \ |
| 139 |
--user=$name-koha.$name-koha" |
161 |
--user=$name-koha.$name-koha" |
| 140 |
|
162 |
|
| 141 |
log_daemon_msg "Restarting Koha worker daemon for $name ($queue)" |
163 |
local job_limits="" |
|
|
164 |
if $job_type; then |
| 165 |
job_limits="--job-type $job_type" |
| 166 |
elif $not_job_type; then |
| 167 |
job_limits="--not-job-type $not_job_type" |
| 168 |
fi |
| 169 |
|
| 170 |
log_daemon_msg "Restarting Koha worker daemon for --queue $queue $job_limits" |
| 142 |
|
171 |
|
| 143 |
if daemon $DAEMONOPTS --restart -- $worker_DAEMON --queue ${queue}; then |
172 |
if daemon $DAEMONOPTS --restart -- $worker_DAEMON --queue ${queue} $job_limits; then |
| 144 |
log_end_msg 0 |
173 |
log_end_msg 0 |
| 145 |
else |
174 |
else |
| 146 |
log_end_msg 1 |
175 |
log_end_msg 1 |
| 147 |
fi |
176 |
fi |
| 148 |
else |
177 |
else |
| 149 |
log_warning_msg "Worker not running for $name ($queue)." |
178 |
log_warning_msg "Worker not running for --queue $queue $job_limits." |
| 150 |
start_worker $name $queue |
179 |
start_worker $name $queue |
| 151 |
fi |
180 |
fi |
| 152 |
} |
181 |
} |
|
Lines 155-166
worker_status()
Link Here
|
| 155 |
{ |
184 |
{ |
| 156 |
local name=$1 |
185 |
local name=$1 |
| 157 |
local queue=$2 |
186 |
local queue=$2 |
|
|
187 |
local job_type=$3 |
| 188 |
local not_job_type=$4 |
| 189 |
|
| 190 |
local job_limits="" |
| 191 |
if $job_type; then |
| 192 |
job_limits="--job-type $job_type" |
| 193 |
elif $not_job_type; then |
| 194 |
job_limits="--not-job-type $not_job_type" |
| 195 |
fi |
| 158 |
|
196 |
|
| 159 |
if is_worker_running ${name} ${queue}; then |
197 |
if is_worker_running ${name} ${queue}; then |
| 160 |
log_daemon_msg "worker running for ${name} ($queue)" |
198 |
log_daemon_msg "worker running for ${name} --queue $queue $job_limits" |
| 161 |
log_end_msg 0 |
199 |
log_end_msg 0 |
| 162 |
else |
200 |
else |
| 163 |
log_daemon_msg "worker not running for ${name} ($queue)" |
201 |
log_daemon_msg "worker not running for ${name} --queue $queue $job_limits" |
| 164 |
log_end_msg 3 |
202 |
log_end_msg 3 |
| 165 |
fi |
203 |
fi |
| 166 |
} |
204 |
} |
|
Lines 177-182
set_action()
Link Here
|
| 177 |
op="" |
215 |
op="" |
| 178 |
queue="default" |
216 |
queue="default" |
| 179 |
quiet="no" |
217 |
quiet="no" |
|
|
218 |
job_type="" |
| 219 |
not_job_type="" |
| 180 |
|
220 |
|
| 181 |
# Read command line parameters |
221 |
# Read command line parameters |
| 182 |
while [ $# -gt 0 ]; do |
222 |
while [ $# -gt 0 ]; do |
|
Lines 202-207
while [ $# -gt 0 ]; do
Link Here
|
| 202 |
--queue) |
242 |
--queue) |
| 203 |
queue="$2" |
243 |
queue="$2" |
| 204 |
shift 2 ;; |
244 |
shift 2 ;; |
|
|
245 |
--type) |
| 246 |
type="$2" |
| 247 |
shift 2 ;; |
| 248 |
--not-type) |
| 249 |
type="$2" |
| 250 |
shift 2 ;; |
| 205 |
-*) |
251 |
-*) |
| 206 |
die "Error: invalid option switch ($1)" ;; |
252 |
die "Error: invalid option switch ($1)" ;; |
| 207 |
*) |
253 |
*) |
|
Lines 231-246
if [ $# -gt 0 ]; then
Link Here
|
| 231 |
|
277 |
|
| 232 |
case $op in |
278 |
case $op in |
| 233 |
"start") |
279 |
"start") |
| 234 |
start_worker $name $queue |
280 |
start_worker $name $queue $job_type $not_job_type |
| 235 |
;; |
281 |
;; |
| 236 |
"stop") |
282 |
"stop") |
| 237 |
stop_worker $name $queue |
283 |
stop_worker $name $queue $job_type $not_job_type |
| 238 |
;; |
284 |
;; |
| 239 |
"restart") |
285 |
"restart") |
| 240 |
restart_worker $name $queue |
286 |
restart_worker $name $queue $job_type $not_job_type |
| 241 |
;; |
287 |
;; |
| 242 |
"status") |
288 |
"status") |
| 243 |
worker_status $name $queue |
289 |
worker_status $name $queue $job_type $not_job_type |
| 244 |
esac |
290 |
esac |
| 245 |
|
291 |
|
| 246 |
else |
292 |
else |