Bugzilla – Attachment 147574 Details for
Bug 33108
We need a way to launch the ES indexer automatically
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33108: koha-es-indexer added
Bug-33108-koha-es-indexer-added.patch (text/plain), 13.56 KB, created by
Tomás Cohen Arazi (tcohen)
on 2023-03-01 19:06:49 UTC
(
hide
)
Description:
Bug 33108: koha-es-indexer added
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2023-03-01 19:06:49 UTC
Size:
13.56 KB
patch
obsolete
>From f4de1805289cf620f4bf56ad3852c69c73371da3 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 1 Mar 2023 10:22:22 -0300 >Subject: [PATCH] Bug 33108: koha-es-indexer added > >--- > debian/docs/koha-es-indexer.xml | 100 ++++++++++++ > debian/koha-common.bash-completion | 1 + > debian/koha-common.install | 1 + > debian/koha-core.install | 1 + > debian/scripts/koha-es-indexer | 247 +++++++++++++++++++++++++++++ > debian/scripts/koha-functions.sh | 28 ++++ > 6 files changed, 378 insertions(+) > create mode 100644 debian/docs/koha-es-indexer.xml > create mode 100755 debian/scripts/koha-es-indexer > >diff --git a/debian/docs/koha-es-indexer.xml b/debian/docs/koha-es-indexer.xml >new file mode 100644 >index 00000000000..abb407ade47 >--- /dev/null >+++ b/debian/docs/koha-es-indexer.xml >@@ -0,0 +1,100 @@ >+<article xmlns='http://docbook.org/ns/docbook'> >+<title>koha-es-indexer</title> >+<info> >+<productname>Koha</productname> is the first free software library automation package. >+<author> >+ <orgname>The Koha Community</orgname> >+ <uri>https://koha-community.org/</uri> >+</author> >+</info> >+ >+<refentry xml:id="koha-es-indexer"> >+ >+ <refmeta> >+ <refentrytitle>koha-es-indexer</refentrytitle> >+ <manvolnum>8</manvolnum> >+ </refmeta> >+ >+ <refnamediv> >+ <refname>koha-es-indexer</refname> >+ <refpurpose>Manage the ES indexer daemon for Koha instances.</refpurpose> >+ <refclass>UNIX/Linux</refclass> >+ </refnamediv> >+ >+ <refsynopsisdiv> >+ <cmdsynopsis> >+ <command>koha-es-indexer</command> >+ <arg choice="req"><option>--start</option>|<option>--stop</option>|<option>--restart</option>|<option>--status</option>|<option>--batch_size</option>|<option>--help</option>|<option>-h</option>|<option>--quiet</option>|<option>-q</option></arg> >+ <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg> >+ </cmdsynopsis> >+ </refsynopsisdiv> >+ >+ <refsect1><title>Options</title> >+ >+ <variablelist> >+ >+ <varlistentry> >+ <term><option>--start</option></term> >+ <listitem> >+ <para>Start the ES indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--stop</option></term> >+ <listitem> >+ <para>Stop the ES indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--restart</option></term> >+ <listitem> >+ <para>Restart the ES indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--batch_size N</option></term> >+ <listitem> >+ <para>Specify the batch size to commit at a time (default: 10).</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--status</option></term> >+ <listitem> >+ <para>Show the status of the ES indexer for the specified instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--quiet|-q</option></term> >+ <listitem> >+ <para>Make the script quiet about non existent instance names. Useful when calling <command>koha-es-indexer</command> from another scripts.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--help|-h</option></term> >+ <listitem> >+ <para>Show usage information.</para> >+ </listitem> >+ </varlistentry> >+ >+ </variablelist> >+ </refsect1> >+ >+ <refsect1><title>Description</title> >+ <para>The <command>koha-es-indexer</command> script lets you manage your Koha instances ES indexer daemon.</para> >+ </refsect1> >+ >+ <refsect1><title>See also</title> >+ <simplelist type="inline"> >+ <member><command>/etc/default/koha-common</command></member> >+ </simplelist> >+ </refsect1> >+ >+</refentry> >+ >+</article> >diff --git a/debian/koha-common.bash-completion b/debian/koha-common.bash-completion >index 94966d360ef..aacb841ea63 100644 >--- a/debian/koha-common.bash-completion >+++ b/debian/koha-common.bash-completion >@@ -257,6 +257,7 @@ _koha-indexer() > return 0 > } > complete -F _koha-indexer koha-indexer >+complete -F _koha-indexer koha-es-indexer > > _koha-zebra() > { >diff --git a/debian/koha-common.install b/debian/koha-common.install >index 2f5c793d11c..2b8c0f4646b 100644 >--- a/debian/koha-common.install >+++ b/debian/koha-common.install >@@ -16,6 +16,7 @@ debian/scripts/koha-elasticsearch usr/sbin > debian/scripts/koha-email-disable usr/sbin > debian/scripts/koha-email-enable usr/sbin > debian/scripts/koha-enable usr/sbin >+debian/scripts/koha-es-indexer usr/sbin > debian/scripts/koha-foreach usr/sbin > debian/scripts/koha-indexer usr/sbin > debian/scripts/koha-list usr/sbin >diff --git a/debian/koha-core.install b/debian/koha-core.install >index 2f5c793d11c..2b8c0f4646b 100644 >--- a/debian/koha-core.install >+++ b/debian/koha-core.install >@@ -16,6 +16,7 @@ debian/scripts/koha-elasticsearch usr/sbin > debian/scripts/koha-email-disable usr/sbin > debian/scripts/koha-email-enable usr/sbin > debian/scripts/koha-enable usr/sbin >+debian/scripts/koha-es-indexer usr/sbin > debian/scripts/koha-foreach usr/sbin > debian/scripts/koha-indexer usr/sbin > debian/scripts/koha-list usr/sbin >diff --git a/debian/scripts/koha-es-indexer b/debian/scripts/koha-es-indexer >new file mode 100755 >index 00000000000..29d78f9664e >--- /dev/null >+++ b/debian/scripts/koha-es-indexer >@@ -0,0 +1,247 @@ >+#!/bin/bash >+# >+# Copyright 2023 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 ES indexing daemon for your Koha instances. >+ >+Usage: >+$scriptname [--start|--stop|--restart] [--batch_size N] [--quiet|-q] instancename1 [instancename2...] >+$scriptname --status instancename1 [instancename2...] >+$scriptname -h|--help >+ >+ --start Start the ES indexing daemon for the specified instances >+ --stop Stop the ES indexing daemon for the specified instances >+ --restart Restart the ES indexing daemon for the specified instances >+ --batch_size N Specify the batch size to commit at a time (default: 10) >+ --status Show the status of the ES indexing 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_es_indexer() >+{ >+ local name=$1 >+ >+ if ! is_es_indexer_running $name; then >+ >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-es-indexer \ >+ --errlog=/var/log/koha/$name/es-indexer-error.log \ >+ --output=/var/log/koha/$name/es-indexer-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Starting Koha ES indexing daemon for $name" >+ >+ if daemon $DAEMONOPTS -- $worker_DAEMON --batch_size ${batch_size}; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: ES indexing daemon already running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+stop_es_indexer() >+{ >+ local name=$1 >+ >+ if is_es_indexer_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-es-indexer \ >+ --errlog=/var/log/koha/$name/es-indexer-error.log \ >+ --output=/var/log/koha/$name/es-indexer-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Stopping Koha ES indexing 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: ES indexing daemon not running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+restart_es_indexer() >+{ >+ local name=$1 >+ local queue=$2 >+ >+ if is_es_indexer_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ DAEMONOPTS="--name=$name-koha-es-indexer \ >+ --errlog=/var/log/koha/$name/es-indexer-error.log \ >+ --output=/var/log/koha/$name/es-indexer-output.log \ >+ --pidfiles=/var/run/koha/$name/ \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Restarting Koha ES indexing daemon for $name" >+ >+ if daemon $DAEMONOPTS --restart -- $worker_DAEMON --batch_size ${batch_size}; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_warning_msg "ES indexing daemon not running for $name." >+ start_es_indexer $name >+ fi >+} >+ >+es_indexer_status() >+{ >+ local name=$1 >+ >+ if is_es_indexer_running $name; then >+ log_daemon_msg "ES indexing daemon running for ${name}" >+ log_end_msg 0 >+ else >+ log_daemon_msg "ES indexing daemon 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" >+batch_size=10 >+ >+# Read command line parameters >+while [ $# -gt 0 ]; do >+ >+ case "$1" in >+ -h|--help) >+ usage ; exit 0 ;; >+ -q|--quiet) >+ quiet="yes" >+ shift ;; >+ --batch_size) >+ batch_size="$2" >+ shift 2 ;; >+ --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/workers/es_indexer_daemon.pl" >+else >+ worker_DAEMON="${KOHA_HOME}/misc/workers/es_indexer_daemon.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_es_indexer $name >+ ;; >+ "stop") >+ stop_es_indexer $name >+ ;; >+ "restart") >+ restart_es_indexer $name >+ ;; >+ "status") >+ es_indexer_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/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh >index 5b81d177ccd..b31b1c67909 100755 >--- a/debian/scripts/koha-functions.sh >+++ b/debian/scripts/koha-functions.sh >@@ -199,6 +199,20 @@ is_indexer_running() > fi > } > >+is_es_indexer_running() >+{ >+ local instancename=$1 >+ >+ if daemon --name="$instancename-koha-es-indexer" \ >+ --pidfiles="/var/run/koha/$instancename/" \ >+ --user="$instancename-koha.$instancename-koha" \ >+ --running ; then >+ return 0 >+ else >+ return 1 >+ fi >+} >+ > is_worker_running() > { > local instancename=$1 >@@ -330,6 +344,20 @@ is_z3950_running() > fi > } > >+is_elasticsearch_enabled() >+{ >+ local instancename=$1 >+ >+ # is querying the DB fails then $searching won't match 'Elasticsearch'. Ditching STDERR >+ search_engine=$(koha-shell $instancename -c "/usr/share/koha/bin/admin/koha-preferences get SearchEngine 2> /dev/null") >+ >+ if [ "$search_engine" = "Elasticsearch" ]; then >+ return 0 >+ else >+ return 1 >+ fi >+} >+ > adjust_paths_dev_install() > { > # Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by >-- >2.39.2
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 33108
:
147560
|
147574
|
147575
|
147576
|
147617
|
147618
|
147619
|
147620
|
147701
|
147702
|
148328
|
148329
|
148330
|
148331
|
148332