Bugzilla – Attachment 182708 Details for
Bug 32736
koha-worker should be able to restart all queues with a single call
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32736: Add --all-queues switch to koha-worker
Bug-32736-Add---all-queues-switch-to-koha-worker.patch (text/plain), 11.42 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-05-21 21:06:45 UTC
(
hide
)
Description:
Bug 32736: Add --all-queues switch to koha-worker
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-05-21 21:06:45 UTC
Size:
11.42 KB
patch
obsolete
>From 3a3ee1491163606358aa24c538d0168982c280f8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 21 May 2025 18:01:23 -0300 >Subject: [PATCH] Bug 32736: Add --all-queues switch to koha-worker > >This patch adds a convenient option switch to the script. It will make >it perform the action (start, stop, restart, print status) on all >defined queues ('default' and 'long_tasks', as of today). > >To test, make sure you applied bug 31124: > >0. Apply this patch >1. Run: > $ ktd --shell --root > k$ cp debian/scripts/koha-functions.sh \ > /usr/share/koha/bin/koha-functions.sh >2. Play with all the options for: > > k$ debian/scripts/koha-worker * kohadev >=> SUCCESS: All options work as expected! > >Note: you should include (say) having `long_tasks` stopped, and starting >all workers with the new parameter. And the same for `--stop` and >`--start`. > >3. Sign off :-D >--- > debian/docs/koha-worker.xml | 7 ++ > debian/scripts/koha-worker | 165 ++++++++++++++++++++---------------- > 2 files changed, 101 insertions(+), 71 deletions(-) > >diff --git a/debian/docs/koha-worker.xml b/debian/docs/koha-worker.xml >index 56a5f0cb82f..d3fef284c8c 100644 >--- a/debian/docs/koha-worker.xml >+++ b/debian/docs/koha-worker.xml >@@ -27,6 +27,7 @@ > <arg><option>--start</option>|<option>--stop</option>|<option>--restart</option></arg> > <arg><option>--status</option></arg> > <arg><option>--queue</option></arg> >+ <arg><option>--all-queues</option></arg> > <arg><option>--quiet</option>|<option>-q</option></arg> > <arg><option>-h</option>|<option>--help</option></arg> > </cmdsynopsis> >@@ -67,6 +68,12 @@ > <para>Note: There used to be a queue called elastic_index, but since the introduction of koha-es-indexer this queue should not be active.</para> > </listitem> > </varlistentry> >+ <varlistentry> >+ <term><option>--all-queues</option></term> >+ <listitem> >+ <para>Makes the requested action to be performed to all defined queues.</para> >+ </listitem> >+ </varlistentry> > <varlistentry> > <term><option>-h</option>|<option>--help</option></term> > <listitem> >diff --git a/debian/scripts/koha-worker b/debian/scripts/koha-worker >index aa51c90c13f..3d799dd0926 100755 >--- a/debian/scripts/koha-worker >+++ b/debian/scripts/koha-worker >@@ -15,8 +15,6 @@ > # 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 >@@ -40,15 +38,17 @@ $scriptname > This script lets you manage the worker daemon for your Koha instances. > > Usage: >-$scriptname [--start|--stop|--restart] [--queue queue_name] [--quiet|-q] instancename1 [instancename2...] >+$scriptname [--start|--stop|--restart] [--queue queue_name|--all-queues] [--quiet|-q] instancename1 [instancename2...] > $scriptname --status 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 >- --queue Specify the queue/worker to restart - 'default' is used if not specified >+ --queue Specify the queue/worker to perform the action on - 'default' is >+ used if not specified (unless --all-queues is passed) > current queues are: default, long_tasks >+ --all-queues Perform the action on all defined queues > --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). >@@ -63,106 +63,119 @@ EOF > start_worker() > { > local name=$1 >- local queue=$2 >+ local queues=$2 > >- if ! is_worker_running $name $queue; then >+ local error_count=0 > >- worker_name=`get_worker_name $name $queue` >+ for queue in $queues; do >+ if ! is_worker_running "$name" "$queue"; then > >- export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ worker_name=$(get_worker_name "$name" "$queue") >+ export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" > >- DAEMONOPTS="--name=${worker_name} \ >- --errlog=/var/log/koha/$name/worker-error.log \ >- --output=/var/log/koha/$name/worker-output.log \ >- --pidfiles=/var/run/koha/$name/ \ >- --verbose=1 --respawn --delay=30 \ >- --user=$name-koha.$name-koha" >+ DAEMONOPTS="--name=${worker_name} \ >+ --errlog=/var/log/koha/${name}/worker-error.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 ($queue)" >+ echo "Starting Koha worker daemon for ${name} (${queue})" > >- if daemon $DAEMONOPTS -- $worker_DAEMON --queue ${queue}; then >- log_end_msg 0 >+ if ! daemon $DAEMONOPTS -- "$worker_DAEMON" --queue "$queue"; then >+ ((error_count++)) >+ fi > else >- log_end_msg 1 >+ echo "Error: worker already running for ${name} (${queue})" >+ ((error_count++)) > fi >- else >- log_daemon_msg "Error: worker already running for $name ($queue)" >- log_end_msg 1 >- fi >+ done >+ >+ log_end_msg $error_count > } > > stop_worker() > { > local name=$1 >- local queue=$2 >+ local queues=$2 > >- if is_worker_running $name $queue; then >- export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ local error_count=0 > >- worker_name=`get_worker_name $name $queue` >+ for queue in $queues; do >+ if is_worker_running "$name" "$queue"; then >+ export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" > >- DAEMONOPTS="--name=${worker_name} \ >- --errlog=/var/log/koha/$name/worker-error.log \ >- --output=/var/log/koha/$name/worker-output.log \ >- --pidfiles=/var/run/koha/$name/ \ >- --verbose=1 --respawn --delay=30 \ >- --user=$name-koha.$name-koha" >+ worker_name=$(get_worker_name "$name" "$queue") > >- log_daemon_msg "Stopping Koha worker daemon for $name ($queue)" >+ DAEMONOPTS="--name=${worker_name} \ >+ --errlog=/var/log/koha/${name}/worker-error.log \ >+ --output=/var/log/koha/${name}/worker-output.log \ >+ --pidfiles=/var/run/koha/${name}/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=${name}-koha.${name}-koha" > >- if daemon $DAEMONOPTS --stop -- $worker_DAEMON --queue ${queue}; then >- log_end_msg 0 >+ echo "Stopping Koha worker daemon for ${name} (${queue})" >+ >+ if ! daemon $DAEMONOPTS --stop -- "$worker_DAEMON" --queue "$queue"; then >+ ((error_count++)) >+ fi > else >- log_end_msg 1 >+ echo "Error: worker not running for ${name} (${queue})" >+ ((error_count++)) > fi >- else >- log_daemon_msg "Error: worker not running for $name ($queue)" >- log_end_msg 1 >- fi >+ done >+ >+ log_end_msg $error_count > } > > restart_worker() > { > local name=$1 >- local queue=$2 >+ local queues=$2 > >- if is_worker_running $name $queue; then >- export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ local error_count=0 > >- worker_name=`get_worker_name $name $queue` >+ for queue in $queues; do >+ if is_worker_running "$name" "$queue"; then >+ export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" > >- DAEMONOPTS="--name=${worker_name} \ >- --errlog=/var/log/koha/$name/worker-error.log \ >- --output=/var/log/koha/$name/worker-output.log \ >- --pidfiles=/var/run/koha/$name/ \ >- --verbose=1 --respawn --delay=30 \ >- --user=$name-koha.$name-koha" >+ worker_name=$(get_worker_name "$name" "$queue") > >- log_daemon_msg "Restarting Koha worker daemon for $name ($queue)" >+ DAEMONOPTS="--name=${worker_name} \ >+ --errlog=/var/log/koha/${name}/worker-error.log \ >+ --output=/var/log/koha/${name}/worker-output.log \ >+ --pidfiles=/var/run/koha/${name}/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=${name}-koha.${name}-koha" > >- if daemon $DAEMONOPTS --restart -- $worker_DAEMON --queue ${queue}; then >- log_end_msg 0 >+ echo "Restarting Koha worker daemon for ${name} (${queue})" >+ >+ if ! daemon $DAEMONOPTS --restart -- "$worker_DAEMON" --queue "$queue"; then >+ ((error_count++)) >+ fi > else >- log_end_msg 1 >+ echo "Worker not running for ${name} (${queue})." >+ start_worker $name $queue > fi >- else >- log_warning_msg "Worker not running for $name ($queue)." >- start_worker $name $queue >- fi >+ done >+ >+ log_end_msg $error_count > } > > worker_status() > { > local name=$1 >- local queue=$2 >+ local queues=$2 > >- if is_worker_running ${name} ${queue}; then >- log_daemon_msg "worker running for ${name} ($queue)" >- log_end_msg 0 >- else >- log_daemon_msg "worker not running for ${name} ($queue)" >- log_end_msg 3 >- fi >+ for queue in $queues; do >+ if is_worker_running "$name" "$queue"; then >+ log_daemon_msg "worker running for ${name} (${queue})" >+ log_end_msg 0 >+ else >+ log_daemon_msg "worker not running for ${name} (${queue})" >+ log_end_msg 3 >+ fi >+ done > } > > set_action() >@@ -177,6 +190,7 @@ set_action() > op="" > queue="default" > quiet="no" >+all_queues="no" > > # Read command line parameters > while [ $# -gt 0 ]; do >@@ -202,6 +216,9 @@ while [ $# -gt 0 ]; do > --queue) > queue="$2" > shift 2 ;; >+ --all-queues) >+ all_queues="yes"; >+ shift ;; > -*) > die "Error: invalid option switch ($1)" ;; > *) >@@ -212,7 +229,7 @@ while [ $# -gt 0 ]; do > done > > # Optionally use alternative paths for a dev install >-adjust_paths_dev_install $1 >+adjust_paths_dev_install "$1" > > if [ "$DEV_INSTALL" = "" ]; then > worker_DAEMON="${KOHA_HOME}/bin/workers/background_jobs_worker.pl" >@@ -229,18 +246,24 @@ if [ $# -gt 0 ]; then > > if is_instance $name; then > >+ if [ "$all_queues" = "yes" ]; then >+ queues=$(get_worker_queues | xargs) >+ else >+ queues=$queue >+ fi >+ > case $op in > "start") >- start_worker $name $queue >+ start_worker "$name" "$queues" > ;; > "stop") >- stop_worker $name $queue >+ stop_worker "$name" "$queues" > ;; > "restart") >- restart_worker $name $queue >+ restart_worker "$name" "$queues" > ;; > "status") >- worker_status $name $queue >+ worker_status "$name" "$queues" > esac > > else >-- >2.49.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 32736
: 182708 |
182710