From f1fef6527c778977bd0d48e2cb42b5c9dc153a8f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 4 Apr 2022 20:23:09 +0200 Subject: [PATCH] Bug 27783: Add queue handling in packaging tools This patch adds queue name handling in is_worker_running and a handy method to centralize process name handling for queue-specific workers. To test: 1. Apply this patch 2. Run: $ source debian/scripts/koha-functions.sh $ get_worker_name kohadev kohadev-koha-worker => SUCCESS: Default queue means no queue name included $ get_worker_name kohadev default kohadev-koha-worker => SUCCESS: Default queue means no queue name included $ get_worker_name kohadev long_tasks kohadev-koha-worker-long_tasks => SUCCESS: Queue name appended to the name 4. Run: $ perl misc4dev/cp_debian_files.pl \ --koha_dir /kohadevbox/koha \ --gitify /kohadevbox/gitify \ --instance kohadev 5. Run: $ koha-worker --start --queue oleonard kohadev => SUCCESS: Starts! 6. Check: $ ps waux | grep oleonard => SUCCESS: It is running 7. Play with --stop, --restart, --status and different queue names, including 'default' and without the --queue param as well. => SUCCESS: All as expected! 8. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- debian/docs/koha-worker.xml | 7 ++++ debian/koha-common.init | 9 +++++ debian/scripts/koha-functions.sh | 17 ++++++++- debian/scripts/koha-worker | 59 ++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/debian/docs/koha-worker.xml b/debian/docs/koha-worker.xml index 3cb19e63cf..42c1ae7fa0 100644 --- a/debian/docs/koha-worker.xml +++ b/debian/docs/koha-worker.xml @@ -26,6 +26,7 @@ koha-worker || + | | @@ -58,6 +59,12 @@ Show status information about worker daemon for named Koha instances. + + + + Allows specifying the queue worker (defaults to 'default'). + + | diff --git a/debian/koha-common.init b/debian/koha-common.init index 4b8e75983f..12a85a64a7 100755 --- a/debian/koha-common.init +++ b/debian/koha-common.init @@ -62,7 +62,10 @@ 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) + # default queue koha-worker --start $(koha-list --enabled) + # long_tasks queue + koha-worker --start --queue long_tasks $(koha-list --enabled) if [ "$USE_INDEXER_DAEMON" = "yes" ]; then koha-indexer --start --quiet $(koha-list --enabled) @@ -79,7 +82,10 @@ 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) + # default queue koha-worker --stop --quiet $(koha-list --enabled) + # long_tasks queue + koha-worker --stop --queue long_tasks --quiet $(koha-list --enabled) if [ "$USE_INDEXER_DAEMON" = "yes" ]; then koha-indexer --stop --quiet $(koha-list --enabled) @@ -94,7 +100,10 @@ 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) + # default queue koha-worker --restart --quiet $(koha-list --enabled) + # long_tasks queue + koha-worker --restart --queue long_tasks --quiet $(koha-list --enabled) if [ "$USE_INDEXER_DAEMON" = "yes" ]; then koha-indexer --restart --quiet $(koha-list --enabled) diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index 8888ad6290..12832cbb9e 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -202,8 +202,11 @@ is_indexer_running() is_worker_running() { local instancename=$1 + local queue=$2 - if daemon --name="$instancename-koha-worker" \ + local name=`get_worker_name $instancename $queue` + + if daemon --name="$name" \ --pidfiles="/var/run/koha/$instancename/" \ --user="$instancename-koha.$instancename-koha" \ --running ; then @@ -213,6 +216,18 @@ is_worker_running() fi } +get_worker_name() +{ + local name=$1 + local queue=$2 + + if [ "$queue" = "" ] || [ "$queue" = "default" ]; then + echo "${name}-koha-worker" + else + echo "${name}-koha-worker-${queue}" + fi +} + is_plack_enabled_opac() { local instancefile=$1 diff --git a/debian/scripts/koha-worker b/debian/scripts/koha-worker index 207d503b55..faecfa662c 100755 --- a/debian/scripts/koha-worker +++ b/debian/scripts/koha-worker @@ -58,11 +58,15 @@ EOF start_worker() { local name=$1 + local queue=$2 + + if ! is_worker_running $name $queue; then + + worker_name=`get_worker_name $name $queue` - if ! is_worker_running $name; then export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - DAEMONOPTS="--name=$name-koha-worker \ + DAEMONOPTS="--name=${worker_name} \ --errlog=/var/log/koha/$name/worker-error.log \ --stdout=/var/log/koha/$name/worker.log \ --output=/var/log/koha/$name/worker-output.log \ @@ -70,15 +74,15 @@ start_worker() --verbose=1 --respawn --delay=30 \ --user=$name-koha.$name-koha" - log_daemon_msg "Starting Koha worker daemon for $name" + log_daemon_msg "Starting Koha worker daemon for $name ($queue)" - if daemon $DAEMONOPTS -- $worker_DAEMON; then + if daemon $DAEMONOPTS -- $worker_DAEMON --job-queue ${queue}; then log_end_msg 0 else log_end_msg 1 fi else - log_daemon_msg "Error: worker already running for $name" + log_daemon_msg "Error: worker already running for $name ($queue)" log_end_msg 1 fi } @@ -86,11 +90,14 @@ start_worker() stop_worker() { local name=$1 + local queue=$2 - if is_worker_running $name; then + if is_worker_running $name $queue; then export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - DAEMONOPTS="--name=$name-koha-worker \ + worker_name=`get_worker_name $name $queue` + + DAEMONOPTS="--name=${worker_name} \ --errlog=/var/log/koha/$name/worker-error.log \ --stdout=/var/log/koha/$name/worker.log \ --output=/var/log/koha/$name/worker-output.log \ @@ -98,15 +105,15 @@ stop_worker() --verbose=1 --respawn --delay=30 \ --user=$name-koha.$name-koha" - log_daemon_msg "Stopping Koha worker daemon for $name" + log_daemon_msg "Stopping Koha worker daemon for $name ($queue)" - if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then + if daemon $DAEMONOPTS --stop -- $worker_DAEMON --job-queue ${queue}; then log_end_msg 0 else log_end_msg 1 fi else - log_daemon_msg "Error: worker not running for $name" + log_daemon_msg "Error: worker not running for $name ($queue)" log_end_msg 1 fi } @@ -114,11 +121,14 @@ stop_worker() restart_worker() { local name=$1 + local queue=$2 - if is_worker_running $name; then + if is_worker_running $name $queue; then export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - DAEMONOPTS="--name=$name-koha-worker \ + worker_name=`get_worker_name $name $queue` + + DAEMONOPTS="--name=${worker_name} \ --errlog=/var/log/koha/$name/worker-error.log \ --stdout=/var/log/koha/$name/worker.log \ --output=/var/log/koha/$name/worker-output.log \ @@ -126,15 +136,15 @@ restart_worker() --verbose=1 --respawn --delay=30 \ --user=$name-koha.$name-koha" - log_daemon_msg "Restarting Koha worker daemon for $name" + log_daemon_msg "Restarting Koha worker daemon for $name ($queue)" - if daemon $DAEMONOPTS --restart -- $worker_DAEMON; then + if daemon $DAEMONOPTS --restart -- $worker_DAEMON --job-queue ${queue}; then log_end_msg 0 else log_end_msg 1 fi else - log_daemon_msg "Error: worker not running for $name" + log_daemon_msg "Error: worker not running for $name ($queue)" log_end_msg 1 fi } @@ -142,12 +152,13 @@ restart_worker() worker_status() { local name=$1 + local queue=$2 - if is_worker_running ${name}; then - log_daemon_msg "worker running for ${name}" + 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}" + log_daemon_msg "worker not running for ${name} ($queue)" log_end_msg 3 fi } @@ -162,6 +173,7 @@ set_action() } op="" +queue="default" quiet="no" # Read command line parameters @@ -185,6 +197,9 @@ while [ $# -gt 0 ]; do --status) set_action "status" shift ;; + --queue) + queue="$2" + shift 2 ;; -*) die "Error: invalid option switch ($1)" ;; *) @@ -214,16 +229,16 @@ if [ $# -gt 0 ]; then case $op in "start") - start_worker $name + start_worker $name $queue ;; "stop") - stop_worker $name + stop_worker $name $queue ;; "restart") - restart_worker $name + restart_worker $name $queue ;; "status") - worker_status $name + worker_status $name $queue esac else -- 2.39.5