Bugzilla – Attachment 109329 Details for
Bug 22417
Add a task queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22417: Add debian script koha-worker
Bug-22417-Add-debian-script-koha-worker.patch (text/plain), 13.16 KB, created by
Marcel de Rooy
on 2020-08-31 08:25:51 UTC
(
hide
)
Description:
Bug 22417: Add debian script koha-worker
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2020-08-31 08:25:51 UTC
Size:
13.16 KB
patch
obsolete
>From fea35477b098a314133ef25d7a5dc4d480f2efbb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 19 Feb 2020 12:03:20 +0100 >Subject: [PATCH] Bug 22417: Add debian script koha-worker >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Cook <dcook@prosentient.com.au> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > debian/docs/koha-common.xml | 8 ++ > debian/koha-common.init | 3 + > debian/scripts/koha-create | 3 + > debian/scripts/koha-disable | 3 + > debian/scripts/koha-functions.sh | 14 +++ > debian/scripts/koha-remove | 4 + > debian/scripts/koha-worker | 242 +++++++++++++++++++++++++++++++++++++++ > misc/background_jobs_worker.pl | 52 +++++++++ > 8 files changed, 329 insertions(+) > create mode 100755 debian/scripts/koha-worker > create mode 100755 misc/background_jobs_worker.pl > >diff --git a/debian/docs/koha-common.xml b/debian/docs/koha-common.xml >index 1bcf180396..5060dec2ac 100644 >--- a/debian/docs/koha-common.xml >+++ b/debian/docs/koha-common.xml >@@ -138,7 +138,15 @@ > <para>Manage the indexer daemon for named Koha instances.</para> > </listitem> > </varlistentry> >+ >+ <varlistentry> >+ <term><option>koha-worker</option></term> >+ <listitem> >+ <para>Manage the worker daemon for named Koha instances.</para> >+ </listitem> >+ </varlistentry> > </variablelist> >+ > </refsect2> > > <refsect2> >diff --git a/debian/koha-common.init b/debian/koha-common.init >index 4ff4c50fbb..4b8e75983f 100755 >--- a/debian/koha-common.init >+++ b/debian/koha-common.init >@@ -62,6 +62,7 @@ do_start() > koha-sip --start $(koha-list --enabled --sip) > koha-plack --start $(koha-list --enabled --plack) > koha-z3950-responder --start --quiet $(koha-list --enabled --z3950) >+ koha-worker --start $(koha-list --enabled) > > if [ "$USE_INDEXER_DAEMON" = "yes" ]; then > koha-indexer --start --quiet $(koha-list --enabled) >@@ -78,6 +79,7 @@ do_stop() > koha-sip --stop $(koha-list --sip) > koha-plack --stop --quiet $(koha-list --enabled --plack) > koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950) >+ koha-worker --stop --quiet $(koha-list --enabled) > > if [ "$USE_INDEXER_DAEMON" = "yes" ]; then > koha-indexer --stop --quiet $(koha-list --enabled) >@@ -92,6 +94,7 @@ do_reload() { > koha-sip --restart $(koha-list --enabled --sip) > koha-plack --restart --quiet $(koha-list --enabled --plack) > koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950) >+ koha-worker --restart --quiet $(koha-list --enabled) > > if [ "$USE_INDEXER_DAEMON" = "yes" ]; then > koha-indexer --restart --quiet $(koha-list --enabled) >diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create >index 390879f37f..0878f3ae31 100755 >--- a/debian/scripts/koha-create >+++ b/debian/scripts/koha-create >@@ -752,6 +752,9 @@ then > # Start Zebra. > koha-zebra --start "$name" > >+ # Start worker >+ koha-worker --start "$name" >+ > if [ "$USE_INDEXER_DAEMON" = "yes" ]; then > # Start Indexer daemon > koha-indexer --start "$name" >diff --git a/debian/scripts/koha-disable b/debian/scripts/koha-disable >index 6332303f0b..c8d699435f 100755 >--- a/debian/scripts/koha-disable >+++ b/debian/scripts/koha-disable >@@ -72,6 +72,9 @@ do > if is_indexer_running $name; then > koha-indexer --stop $name > fi >+ if is_worker_running $name; then >+ koha-worker --stop $name >+ fi > elif [ "$RET" = 2 ]; then > warn "Error: Apache configuration file not present for instance $name." > else >diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh >index 082d3628fa..f82ebfcc80 100755 >--- a/debian/scripts/koha-functions.sh >+++ b/debian/scripts/koha-functions.sh >@@ -199,6 +199,20 @@ is_indexer_running() > fi > } > >+is_worker_running() >+{ >+ local instancename=$1 >+ >+ if daemon --name="$instancename-koha-worker" \ >+ --pidfiles="/var/run/koha/$instancename/" \ >+ --user="$instancename-koha.$instancename-koha" \ >+ --running ; then >+ return 0 >+ else >+ return 1 >+ fi >+} >+ > is_plack_enabled_opac() > { > local instancefile=$1 >diff --git a/debian/scripts/koha-remove b/debian/scripts/koha-remove >index d68ba7d6bf..7270661bc4 100755 >--- a/debian/scripts/koha-remove >+++ b/debian/scripts/koha-remove >@@ -81,6 +81,10 @@ eof > if is_indexer_running $name; then > koha-indexer --stop $name || /bin/true > fi >+ # Stop the worker daemon if needed >+ if is_worker_running $name; then >+ koha-worker --stop $name || /bin/true >+ fi > # Stop the Plack server if needed > if is_plack_running $name; then > koha-plack --stop $name || /bin/true >diff --git a/debian/scripts/koha-worker b/debian/scripts/koha-worker >new file mode 100755 >index 0000000000..b4df12859f >--- /dev/null >+++ b/debian/scripts/koha-worker >@@ -0,0 +1,242 @@ >+#!/bin/bash >+# >+# Copyright 2020 Koha Development team >+# >+# 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 >+ >+. /lib/lsb/init-functions >+ >+# Read configuration variable file if it is present >+[ -r /etc/default/koha-common ] && . /etc/default/koha-common >+ >+# include helper functions >+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then >+ . "/usr/share/koha/bin/koha-functions.sh" >+else >+ echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 >+ exit 1 >+fi >+ >+usage() >+{ >+ local scriptname=$(basename $0) >+ >+ cat <<EOF >+$scriptname >+ >+This script lets you manage the worker daemon for your Koha instances. >+ >+Usage: >+$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...] >+$scriptname -h|--help >+ >+ --start Start the worker daemon for the specified instances >+ --stop Stop the worker daemon for the specified instances >+ --restart Restart the worker daemon for the specified instances >+ --status Show the status of the worker for the specified instances >+ --quiet|-q Make the script quiet about non existent instance names >+ (useful for calling from another scripts). >+ --help|-h Display this help message >+ >+EOF >+} >+ >+start_worker() >+{ >+ local name=$1 >+ >+ if ! is_worker_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-worker \ >+ --errlog=/var/log/koha/$name/worker-error.log \ >+ --stdout=/var/log/koha/$name/worker.log \ >+ --output=/var/log/koha/$name/worker-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Starting Koha worker daemon for $name" >+ >+ if daemon $DAEMONOPTS -- $worker_DAEMON; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: worker already running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+stop_worker() >+{ >+ local name=$1 >+ >+ if is_worker_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-worker \ >+ --errlog=/var/log/koha/$name/worker-error.log \ >+ --stdout=/var/log/koha/$name/worker.log \ >+ --output=/var/log/koha/$name/worker-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Stopping Koha worker daemon for $name" >+ >+ if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: worker not running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+restart_worker() >+{ >+ local name=$1 >+ >+ if is_worker_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-worker \ >+ --errlog=/var/log/koha/$name/worker-error.log \ >+ --stdout=/var/log/koha/$name/worker.log \ >+ --output=/var/log/koha/$name/worker-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Restarting Koha worker daemon for $name" >+ >+ if daemon $DAEMONOPTS --restart -- $worker_DAEMON; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: worker not running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+worker_status() >+{ >+ local name=$1 >+ >+ if is_worker_running ${name}; then >+ log_daemon_msg "worker running for ${name}" >+ log_end_msg 0 >+ else >+ log_daemon_msg "worker not running for ${name}" >+ log_end_msg 3 >+ fi >+} >+ >+set_action() >+{ >+ if [ "$op" = "" ]; then >+ op=$1 >+ else >+ die "Error: only one action can be specified." >+ fi >+} >+ >+op="" >+quiet="no" >+ >+# Read command line parameters >+while [ $# -gt 0 ]; do >+ >+ case "$1" in >+ -h|--help) >+ usage ; exit 0 ;; >+ -q|--quiet) >+ quiet="yes" >+ shift ;; >+ --start) >+ set_action "start" >+ shift ;; >+ --stop) >+ set_action "stop" >+ shift ;; >+ --restart) >+ set_action "restart" >+ shift ;; >+ --status) >+ set_action "status" >+ shift ;; >+ -*) >+ die "Error: invalid option switch ($1)" ;; >+ *) >+ # We expect the remaining stuff are the instance names >+ break ;; >+ esac >+ >+done >+ >+# Optionally use alternative paths for a dev install >+adjust_paths_dev_install $1 >+ >+if [ "$DEV_INSTALL" = "" ]; then >+ worker_DAEMON="${KOHA_HOME}/bin/background_jobs_worker.pl" >+else >+ worker_DAEMON="${KOHA_HOME}/misc/background_jobs_worker.pl" >+fi >+ >+# PERL5LIB has been read from etc/default >+export PERL5LIB >+ >+if [ $# -gt 0 ]; then >+ # We have at least one instance name >+ for name in "$@"; do >+ >+ if is_instance $name; then >+ >+ case $op in >+ "start") >+ start_worker $name >+ ;; >+ "stop") >+ stop_worker $name >+ ;; >+ "restart") >+ restart_worker $name >+ ;; >+ "status") >+ worker_status $name >+ esac >+ >+ else >+ if [ "$quiet" = "no" ]; then >+ log_daemon_msg "Error: Invalid instance name $name" >+ log_end_msg 1 >+ fi >+ fi >+ >+ done >+else >+ if [ "$quiet" = "no" ]; then >+ warn "Error: you must provide at least one instance name" >+ fi >+fi >+ >+exit 0 >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >new file mode 100755 >index 0000000000..2d7264b139 >--- /dev/null >+++ b/misc/background_jobs_worker.pl >@@ -0,0 +1,52 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha 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. >+# >+# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use JSON qw( encode_json decode_json ); >+ >+use Koha::BackgroundJob::BatchUpdateBiblio; >+use Koha::BackgroundJob; >+ >+my $conn = Koha::BackgroundJob->connect; >+ >+my $channel = $conn->open_channel(); >+ >+my $job_type = 'batch_biblio_record_modification'; >+$channel->declare_queue( >+ queue => $job_type, >+ durable => 1, >+); >+ >+$channel->qos(prefetch_count => 1,); >+ >+$channel->consume( >+ on_consume => sub { >+ my $var = shift; >+ my $body = $var->{body}->{payload}; >+ say " [x] Received $body"; >+ >+ my $args = decode_json( $body ); >+ >+ Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel); >+ say " [x] Done"; >+ }, >+ no_ack => 0, >+); >+ >+warn "waiting forever"; >+# Wait forever >+AnyEvent->condvar->recv; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22417
:
105542
|
105543
|
107385
|
107386
|
107387
|
107388
|
107389
|
107390
|
107391
|
107392
|
107393
|
107394
|
107395
|
107396
|
107397
|
107398
|
107399
|
107400
|
107401
|
107402
|
107403
|
107404
|
107405
|
107406
|
107481
|
107482
|
107682
|
108023
|
108024
|
108025
|
108026
|
108027
|
108028
|
108029
|
108030
|
108031
|
108032
|
108033
|
108034
|
108035
|
108036
|
108037
|
108038
|
108039
|
108040
|
108041
|
108042
|
108043
|
108044
|
108045
|
108046
|
108047
|
109270
|
109271
|
109319
|
109320
|
109321
|
109322
|
109323
|
109324
|
109325
|
109326
|
109327
|
109328
|
109329
|
109330
|
109331
|
109332
|
109333
|
109334
|
109335
|
109336
|
109337
|
109338
|
109339
|
109340
|
109341
|
109342
|
109343
|
109344
|
109345
|
109350
|
109351
|
109355
|
109390
|
109391
|
109392
|
109393
|
109394
|
109395
|
109396
|
109397
|
109398
|
109399
|
109400
|
109401
|
109402
|
109403
|
109404
|
109405
|
109406
|
109407
|
109408
|
109409
|
109410
|
109411
|
109412
|
109413
|
109414
|
109415
|
109416
|
109417
|
109418
|
109474
|
109475
|
109476
|
109477
|
110150
|
111091
|
111092
|
111093
|
111094
|
111095
|
111096
|
111097
|
111098
|
111099
|
111100
|
111101
|
111102
|
111103
|
111104
|
111105
|
111106
|
111107
|
111108
|
111109
|
111110
|
111111
|
111112
|
111113
|
111114
|
111115
|
111116
|
111117
|
111118
|
111119
|
111120
|
111121
|
111238
|
111239
|
111245