View | Details | Raw Unified | Return to bug 33108
Collapse All | Expand All

(-)a/debian/docs/koha-es-indexer.xml (+100 lines)
Line 0 Link Here
1
<article xmlns='http://docbook.org/ns/docbook'>
2
<title>koha-es-indexer</title>
3
<info>
4
<productname>Koha</productname> is the first free software library automation package.
5
<author>
6
  <orgname>The Koha Community</orgname>
7
  <uri>https://koha-community.org/</uri>
8
</author>
9
</info>
10
11
<refentry xml:id="koha-es-indexer">
12
13
  <refmeta>
14
    <refentrytitle>koha-es-indexer</refentrytitle>
15
    <manvolnum>8</manvolnum>
16
  </refmeta>
17
18
  <refnamediv>
19
    <refname>koha-es-indexer</refname>
20
    <refpurpose>Manage the ES indexer daemon for Koha instances.</refpurpose>
21
    <refclass>UNIX/Linux</refclass>
22
  </refnamediv>
23
24
  <refsynopsisdiv>
25
    <cmdsynopsis>
26
      <command>koha-es-indexer</command>
27
      <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>
28
      <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
29
    </cmdsynopsis>
30
  </refsynopsisdiv>
31
32
  <refsect1><title>Options</title>
33
34
  <variablelist>
35
36
    <varlistentry>
37
      <term><option>--start</option></term>
38
      <listitem>
39
        <para>Start the ES indexer daemon for the desired Koha instances.</para>
40
      </listitem>
41
    </varlistentry>
42
43
    <varlistentry>
44
      <term><option>--stop</option></term>
45
      <listitem>
46
        <para>Stop the ES indexer daemon for the desired Koha instances.</para>
47
      </listitem>
48
    </varlistentry>
49
50
    <varlistentry>
51
      <term><option>--restart</option></term>
52
      <listitem>
53
        <para>Restart the ES indexer daemon for the desired Koha instances.</para>
54
      </listitem>
55
    </varlistentry>
56
57
    <varlistentry>
58
      <term><option>--batch_size N</option></term>
59
      <listitem>
60
        <para>Specify the batch size to commit at a time (default: 10).</para>
61
      </listitem>
62
    </varlistentry>
63
64
    <varlistentry>
65
      <term><option>--status</option></term>
66
      <listitem>
67
        <para>Show the status of the ES indexer for the specified instances.</para>
68
      </listitem>
69
    </varlistentry>
70
71
    <varlistentry>
72
      <term><option>--quiet|-q</option></term>
73
      <listitem>
74
        <para>Make the script quiet about non existent instance names. Useful when calling <command>koha-es-indexer</command> from another scripts.</para>
75
      </listitem>
76
    </varlistentry>
77
78
    <varlistentry>
79
      <term><option>--help|-h</option></term>
80
      <listitem>
81
        <para>Show usage information.</para>
82
      </listitem>
83
    </varlistentry>
84
85
  </variablelist>
86
  </refsect1>
87
88
  <refsect1><title>Description</title>
89
    <para>The <command>koha-es-indexer</command> script lets you manage your Koha instances ES indexer daemon.</para>
90
  </refsect1>
91
92
  <refsect1><title>See also</title>
93
  <simplelist type="inline">
94
    <member><command>/etc/default/koha-common</command></member>
95
  </simplelist>
96
  </refsect1>
97
98
</refentry>
99
100
</article>
(-)a/debian/koha-common.bash-completion (+1 lines)
Lines 257-262 _koha-indexer() Link Here
257
    return 0
257
    return 0
258
}
258
}
259
complete -F _koha-indexer koha-indexer
259
complete -F _koha-indexer koha-indexer
260
complete -F _koha-indexer koha-es-indexer
260
261
261
_koha-zebra()
262
_koha-zebra()
262
{
263
{
(-)a/debian/koha-common.install (+1 lines)
Lines 16-21 debian/scripts/koha-elasticsearch usr/sbin Link Here
16
debian/scripts/koha-email-disable           usr/sbin
16
debian/scripts/koha-email-disable           usr/sbin
17
debian/scripts/koha-email-enable            usr/sbin
17
debian/scripts/koha-email-enable            usr/sbin
18
debian/scripts/koha-enable                  usr/sbin
18
debian/scripts/koha-enable                  usr/sbin
19
debian/scripts/koha-es-indexer              usr/sbin
19
debian/scripts/koha-foreach                 usr/sbin
20
debian/scripts/koha-foreach                 usr/sbin
20
debian/scripts/koha-indexer                 usr/sbin
21
debian/scripts/koha-indexer                 usr/sbin
21
debian/scripts/koha-list                    usr/sbin
22
debian/scripts/koha-list                    usr/sbin
(-)a/debian/koha-core.install (+1 lines)
Lines 16-21 debian/scripts/koha-elasticsearch usr/sbin Link Here
16
debian/scripts/koha-email-disable           usr/sbin
16
debian/scripts/koha-email-disable           usr/sbin
17
debian/scripts/koha-email-enable            usr/sbin
17
debian/scripts/koha-email-enable            usr/sbin
18
debian/scripts/koha-enable                  usr/sbin
18
debian/scripts/koha-enable                  usr/sbin
19
debian/scripts/koha-es-indexer              usr/sbin
19
debian/scripts/koha-foreach                 usr/sbin
20
debian/scripts/koha-foreach                 usr/sbin
20
debian/scripts/koha-indexer                 usr/sbin
21
debian/scripts/koha-indexer                 usr/sbin
21
debian/scripts/koha-list                    usr/sbin
22
debian/scripts/koha-list                    usr/sbin
(-)a/debian/scripts/koha-es-indexer (+247 lines)
Line 0 Link Here
1
#!/bin/bash
2
#
3
# Copyright 2023 Koha Development team
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
set -e
19
20
. /lib/lsb/init-functions
21
22
# Read configuration variable file if it is present
23
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
24
25
# include helper functions
26
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
27
    . "/usr/share/koha/bin/koha-functions.sh"
28
else
29
    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
30
    exit 1
31
fi
32
33
usage()
34
{
35
    local scriptname=$(basename $0)
36
37
    cat <<EOF
38
$scriptname
39
40
This script lets you manage the ES indexing daemon for your Koha instances.
41
42
Usage:
43
$scriptname [--start|--stop|--restart] [--batch_size N] [--quiet|-q] instancename1 [instancename2...]
44
$scriptname --status instancename1 [instancename2...]
45
$scriptname -h|--help
46
47
    --start               Start the ES indexing daemon for the specified instances
48
    --stop                Stop the ES indexing daemon for the specified instances
49
    --restart             Restart the ES indexing daemon for the specified instances
50
    --batch_size N        Specify the batch size to commit at a time (default: 10)
51
    --status              Show the status of the ES indexing for the specified instances
52
    --quiet|-q            Make the script quiet about non existent instance names
53
                          (useful for calling from another scripts).
54
    --help|-h             Display this help message
55
56
EOF
57
}
58
59
start_es_indexer()
60
{
61
    local name=$1
62
63
    if ! is_es_indexer_running $name; then
64
65
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
66
67
        DAEMONOPTS="--name=$name-koha-es-indexer \
68
            --errlog=/var/log/koha/$name/es-indexer-error.log \
69
            --output=/var/log/koha/$name/es-indexer-output.log \
70
            --pidfiles=/var/run/koha/$name/ \
71
            --verbose=1 --respawn --delay=30 \
72
            --user=$name-koha.$name-koha"
73
74
        log_daemon_msg "Starting Koha ES indexing daemon for $name"
75
76
        if daemon $DAEMONOPTS -- $worker_DAEMON --batch_size ${batch_size}; then
77
            log_end_msg 0
78
        else
79
            log_end_msg 1
80
        fi
81
    else
82
        log_daemon_msg "Error: ES indexing daemon already running for $name"
83
        log_end_msg 1
84
    fi
85
}
86
87
stop_es_indexer()
88
{
89
    local name=$1
90
91
    if is_es_indexer_running $name; then
92
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
93
94
        DAEMONOPTS="--name=$name-koha-es-indexer \
95
            --errlog=/var/log/koha/$name/es-indexer-error.log \
96
            --output=/var/log/koha/$name/es-indexer-output.log \
97
            --pidfiles=/var/run/koha/$name/ \
98
            --verbose=1 --respawn --delay=30 \
99
            --user=$name-koha.$name-koha"
100
101
        log_daemon_msg "Stopping Koha ES indexing daemon for $name"
102
103
        if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then
104
            log_end_msg 0
105
        else
106
            log_end_msg 1
107
        fi
108
    else
109
        log_daemon_msg "Error: ES indexing daemon not running for $name"
110
        log_end_msg 1
111
    fi
112
}
113
114
restart_es_indexer()
115
{
116
    local name=$1
117
    local queue=$2
118
119
    if is_es_indexer_running $name; then
120
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
121
122
        DAEMONOPTS="--name=$name-koha-es-indexer \
123
            --errlog=/var/log/koha/$name/es-indexer-error.log \
124
            --output=/var/log/koha/$name/es-indexer-output.log \
125
            --pidfiles=/var/run/koha/$name/ \
126
            --verbose=1 --respawn --delay=30 \
127
            --user=$name-koha.$name-koha"
128
129
        log_daemon_msg "Restarting Koha ES indexing daemon for $name"
130
131
        if daemon $DAEMONOPTS --restart -- $worker_DAEMON --batch_size ${batch_size}; then
132
            log_end_msg 0
133
        else
134
            log_end_msg 1
135
        fi
136
    else
137
        log_warning_msg "ES indexing daemon not running for $name."
138
        start_es_indexer $name
139
    fi
140
}
141
142
es_indexer_status()
143
{
144
    local name=$1
145
146
    if is_es_indexer_running $name; then
147
        log_daemon_msg "ES indexing daemon running for ${name}"
148
        log_end_msg 0
149
    else
150
        log_daemon_msg "ES indexing daemon not running for ${name}"
151
        log_end_msg 3
152
    fi
153
}
154
155
set_action()
156
{
157
    if [ "$op" = "" ]; then
158
        op=$1
159
    else
160
        die "Error: only one action can be specified."
161
    fi
162
}
163
164
op=""
165
quiet="no"
166
batch_size=10
167
168
# Read command line parameters
169
while [ $# -gt 0 ]; do
170
171
    case "$1" in
172
        -h|--help)
173
            usage ; exit 0 ;;
174
        -q|--quiet)
175
            quiet="yes"
176
            shift ;;
177
        --batch_size)
178
            batch_size="$2"
179
            shift 2 ;;
180
        --start)
181
            set_action "start"
182
            shift ;;
183
        --stop)
184
            set_action "stop"
185
            shift ;;
186
        --restart)
187
            set_action "restart"
188
            shift ;;
189
        --status)
190
            set_action "status"
191
            shift ;;
192
        -*)
193
            die "Error: invalid option switch ($1)" ;;
194
        *)
195
            # We expect the remaining stuff are the instance names
196
            break ;;
197
    esac
198
199
done
200
201
# Optionally use alternative paths for a dev install
202
adjust_paths_dev_install $1
203
204
if [ "$DEV_INSTALL" = "" ]; then
205
    worker_DAEMON="${KOHA_HOME}/bin/workers/es_indexer_daemon.pl"
206
else
207
    worker_DAEMON="${KOHA_HOME}/misc/workers/es_indexer_daemon.pl"
208
fi
209
210
# PERL5LIB has been read from etc/default
211
export PERL5LIB
212
213
if [ $# -gt 0 ]; then
214
    # We have at least one instance name
215
    for name in "$@"; do
216
217
        if is_instance $name; then
218
219
            case $op in
220
                "start")
221
                    start_es_indexer $name
222
                    ;;
223
                "stop")
224
                    stop_es_indexer $name
225
                    ;;
226
                "restart")
227
                    restart_es_indexer $name
228
                    ;;
229
                "status")
230
                    es_indexer_status $name
231
            esac
232
233
        else
234
            if [ "$quiet" = "no" ]; then
235
                log_daemon_msg "Error: Invalid instance name $name"
236
                log_end_msg 1
237
            fi
238
        fi
239
240
    done
241
else
242
    if [ "$quiet" = "no" ]; then
243
        warn "Error: you must provide at least one instance name"
244
    fi
245
fi
246
247
exit 0
(-)a/debian/scripts/koha-functions.sh (-1 / +28 lines)
Lines 199-204 is_indexer_running() Link Here
199
    fi
199
    fi
200
}
200
}
201
201
202
is_es_indexer_running()
203
{
204
    local instancename=$1
205
206
    if daemon --name="$instancename-koha-es-indexer" \
207
            --pidfiles="/var/run/koha/$instancename/" \
208
            --user="$instancename-koha.$instancename-koha" \
209
            --running ; then
210
        return 0
211
    else
212
        return 1
213
    fi
214
}
215
202
is_worker_running()
216
is_worker_running()
203
{
217
{
204
    local instancename=$1
218
    local instancename=$1
Lines 330-335 is_z3950_running() Link Here
330
    fi
344
    fi
331
}
345
}
332
346
347
is_elasticsearch_enabled()
348
{
349
    local instancename=$1
350
351
    # is querying the DB fails then $searching won't match 'Elasticsearch'. Ditching STDERR
352
    search_engine=$(koha-shell $instancename -c "/usr/share/koha/bin/admin/koha-preferences get SearchEngine 2> /dev/null")
353
354
    if [ "$search_engine" = "Elasticsearch" ]; then
355
        return 0
356
    else
357
        return 1
358
    fi
359
}
360
333
adjust_paths_dev_install()
361
adjust_paths_dev_install()
334
{
362
{
335
# Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by
363
# Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by
336
- 

Return to bug 33108