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

(-)a/debian/docs/koha-common.xml (+7 lines)
Lines 145-150 Link Here
145
          <para>Stop Zebra for named Koha instances.</para>
145
          <para>Stop Zebra for named Koha instances.</para>
146
        </listitem>
146
        </listitem>
147
      </varlistentry>
147
      </varlistentry>
148
149
      <varlistentry>
150
        <term><option>koha-indexer</option></term>
151
        <listitem>
152
          <para>Manage the indexer daemon for named Koha instances.</para>
153
        </listitem>
154
      </varlistentry>
148
    </variablelist>
155
    </variablelist>
149
    </refsect2>
156
    </refsect2>
150
157
(-)a/debian/docs/koha-indexer.xml (+86 lines)
Line 0 Link Here
1
<article xmlns='http://docbook.org/ns/docbook'>
2
<title>koha-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>http://koha-community.org/</uri>
8
</author>
9
</info>
10
11
<refentry xml:id="koha-indexer">
12
13
  <refmeta>
14
    <refentrytitle>koha-indexer</refentrytitle>
15
    <manvolnum>8</manvolnum>
16
  </refmeta>
17
18
  <refnamediv>
19
    <refname>koha-indexer</refname>
20
    <refpurpose>Manage the indexer daemon for Koha instances.</refpurpose>
21
    <refclass>UNIX/Linux</refclass>
22
  </refnamediv>
23
24
  <refsynopsisdiv>
25
    <cmdsynopsis>
26
      <command>koha-indexer</command>
27
      <arg choice="req"><option>--start</option>|<option>--stop</option>|<option>--restart</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 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 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 indexer daemon for the desired Koha instances.</para>
54
      </listitem>
55
    </varlistentry>
56
57
    <varlistentry>
58
      <term><option>--quiet|-q</option></term>
59
      <listitem>
60
        <para>Make the script quiet about non existent instance names. Useful when calling <command>koha-indexer</command> from another scripts.</para>
61
      </listitem>
62
    </varlistentry>
63
64
    <varlistentry>
65
      <term><option>--help|-h</option></term>
66
      <listitem>
67
        <para>Show usage information.</para>
68
      </listitem>
69
    </varlistentry>
70
71
  </variablelist>
72
  </refsect1>
73
74
  <refsect1><title>Description</title>
75
    <para>The <command>koha-indexer</command> script lets you manage your Koha instances indexer daemon.</para>
76
  </refsect1>
77
78
  <refsect1><title>See also</title>
79
  <simplelist type="inline">
80
    <member><command>/etc/default/koha-common</command></member>
81
  </simplelist>
82
  </refsect1>
83
84
</refentry>
85
86
</article>
(-)a/debian/koha-common.cron.d (+1 lines)
Lines 6-10 Link Here
6
SHELL=/bin/sh
6
SHELL=/bin/sh
7
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
7
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
8
8
9
# Comment the following line if you want to use the experimental koha-index-daemon integration
9
*/5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra -q $(koha-list --enabled)
10
*/5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra -q $(koha-list --enabled)
10
*/15 * * * * root koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/process_message_queue.pl
11
*/15 * * * * root koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/process_message_queue.pl
(-)a/debian/koha-common.default (-1 / +36 lines)
Lines 1-5 Link Here
1
## General koha-common default options
1
## General koha-common default options file
2
2
3
PERL5LIB="/usr/share/koha/lib"
3
PERL5LIB="/usr/share/koha/lib"
4
KOHA_HOME="/usr/share/koha"
5
6
## Background record indexing
7
#
8
# The following options control the use of an indexing daemon for
9
# Koha instances.
10
#
11
# More information can be found here:
12
#
13
#     http://wiki.koha-community.org/wiki/PackagesIndexDaemon
14
#
15
# IMPORTANT: You should comment the relevant line in /etc/cron.d/koha-common
16
#            (the one that calls koha-rebuild-zebra)
17
#
18
# USE_INDEXER_DAEMON: "no" | "yes"
19
#
20
USE_INDEXER_DAEMON="no"
21
22
# Set an alternate indexer daemon. The default is to use the rebuild_zebra.pl
23
# in daemon mode.
24
#
25
# Example: ALTERNATE_INDEXER_DAEMON="koha-index-daemon"
26
#
27
# ALTERNATE_INDEXER_DAEMON=""
28
29
# Lookup/indexing frecquency (in seconds) for the indexing daemon.
30
#
31
# The default value is 5
32
#
33
INDEXER_TIMEOUT=5
34
35
# Parameters to be passed to the indexer daemon. Useful for alternate indexers.
36
# Defaults to INDEXER_PARAMS="-daemon -x -sleep $INDEXER_TIMEOUT"
37
#
38
# INDEXER_PARAMS=""
4
39
5
## End of general koha-common default options
40
## End of general koha-common default options
(-)a/debian/koha-common.init (+12 lines)
Lines 49-54 do_start() Link Here
49
    koha-create-dirs $(koha-list)
49
    koha-create-dirs $(koha-list)
50
    koha-start-zebra $(koha-list --enabled)
50
    koha-start-zebra $(koha-list --enabled)
51
    koha-start-sip $(koha-list --enabled)
51
    koha-start-sip $(koha-list --enabled)
52
53
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
54
        koha-indexer --start --quiet $(koha-list --enabled)
55
    fi
52
}
56
}
53
57
54
#
58
#
Lines 59-64 do_stop() Link Here
59
    # We stop everything, including disabled ones.
63
    # We stop everything, including disabled ones.
60
    koha-stop-zebra $(koha-list) || true
64
    koha-stop-zebra $(koha-list) || true
61
    koha-stop-sip $(koha-list) || true
65
    koha-stop-sip $(koha-list) || true
66
67
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
68
        koha-indexer --stop --quiet $(koha-list --enabled)
69
    fi
62
}
70
}
63
71
64
#
72
#
Lines 68-73 do_reload() { Link Here
68
    koha-restart-zebra $(koha-list --enabled)
76
    koha-restart-zebra $(koha-list --enabled)
69
    koha-stop-sip $(koha-list) || true
77
    koha-stop-sip $(koha-list) || true
70
    koha-start-sip $(koha-list --enabled)
78
    koha-start-sip $(koha-list --enabled)
79
80
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
81
        koha-indexer --restart --quiet $(koha-list --enabled)
82
    fi
71
}
83
}
72
84
73
#
85
#
(-)a/debian/koha-common.install (+1 lines)
Lines 17-22 debian/scripts/koha-email-disable usr/sbin Link Here
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-foreach                 usr/sbin
19
debian/scripts/koha-foreach                 usr/sbin
20
debian/scripts/koha-indexer                 usr/sbin
20
debian/scripts/koha-list                    usr/sbin
21
debian/scripts/koha-list                    usr/sbin
21
debian/scripts/koha-mysql                   usr/sbin
22
debian/scripts/koha-mysql                   usr/sbin
22
debian/scripts/koha-rebuild-zebra           usr/sbin
23
debian/scripts/koha-rebuild-zebra           usr/sbin
(-)a/debian/scripts/koha-create (+7 lines)
Lines 16-21 Link Here
16
# You should have received a copy of the GNU General Public License
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
19
# Read configuration variable file if it is present
20
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
19
21
20
set -e
22
set -e
21
23
Lines 642-647 then Link Here
642
644
643
    # Start Zebra.
645
    # Start Zebra.
644
    koha-start-zebra "$name"
646
    koha-start-zebra "$name"
647
648
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
649
        # Start Indexer daemon
650
        koha-indexer --start "$name"
651
    fi
645
fi
652
fi
646
653
647
654
(-)a/debian/scripts/koha-functions.sh (+13 lines)
Lines 108-113 is_zebra_running() Link Here
108
    fi
108
    fi
109
}
109
}
110
110
111
is_indexer_running()
112
{
113
    local instancename=$1
114
115
    if daemon --name="$instancename-koha-indexer" \
116
            --user="$instancename-koha.$instancename-koha" \
117
            --running ; then
118
        return 0
119
    else
120
        return 1
121
    fi
122
}
123
111
get_instances()
124
get_instances()
112
{
125
{
113
    find /etc/koha/sites -mindepth 1 -maxdepth 1\
126
    find /etc/koha/sites -mindepth 1 -maxdepth 1\
(-)a/debian/scripts/koha-indexer (-1 / +233 lines)
Line 0 Link Here
0
- 
1
#!/bin/bash
2
#
3
# koha-indexer - Manage Indexer Daemons for Koha instances
4
# Copyright 2014 Tomás Cohen Arazi @ Universidad Nacional de Córdoba
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
set -e
20
21
. /lib/lsb/init-functions
22
23
# Read configuration variable file if it is present
24
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
25
26
# include helper functions
27
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
28
    . "/usr/share/koha/bin/koha-functions.sh"
29
else
30
    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
31
    exit 1
32
fi
33
34
usage()
35
{
36
    local scriptname=$(basename $0)
37
38
    cat <<EOF
39
$scriptname
40
41
This script lets you manage the indexer daemon for your Koha instances.
42
43
Usage:
44
$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...]
45
$scriptname -h|--help
46
47
    --start               Start the indexer daemon for the specified instances
48
    --stop                Stop the indexer daemon for the specified instances
49
    --restart             Restart the indexer daemon for the specified instances
50
    --quiet|-q            Make the script quiet about non existent instance names
51
                          (useful for calling from another scripts).
52
    --help|-h             Display this help message
53
54
EOF
55
}
56
57
start_indexer()
58
{
59
    local name=$1
60
61
    if ! is_indexer_running $name; then
62
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
63
64
        DAEMONOPTS="--name=$name-koha-indexer \
65
            --errlog=/var/log/koha/$name/indexer-error.log \
66
            --stdout=/var/log/koha/$name/indexer.log \
67
            --output=/var/log/koha/$name/indexer-output.log \
68
            --verbose=1 --respawn --delay=30 \
69
            --user=$name-koha.$name-koha"
70
71
        log_daemon_msg "Starting Koha indexing daemon for $name"
72
73
        if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then
74
            log_end_msg 0
75
        else
76
            log_end_msg 1
77
        fi
78
    else
79
        log_daemon_msg "Error: Indexer already running for $name"
80
        log_end_msg 1
81
    fi
82
}
83
84
stop_indexer()
85
{
86
    local name=$1
87
88
    if is_indexer_running $name; then
89
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
90
91
        DAEMONOPTS="--name=$name-koha-indexer \
92
            --errlog=/var/log/koha/$name/indexer-error.log \
93
            --stdout=/var/log/koha/$name/indexer.log \
94
            --output=/var/log/koha/$name/indexer-output.log \
95
            --verbose=1 --respawn --delay=30 \
96
            --user=$name-koha.$name-koha"
97
98
        log_daemon_msg "Stopping Koha indexing daemon for $name"
99
100
        if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then
101
            log_end_msg 0
102
        else
103
            log_end_msg 1
104
        fi
105
    else
106
        log_daemon_msg "Error: Indexer not running for $name"
107
        log_end_msg 1
108
    fi
109
}
110
111
restart_indexer()
112
{
113
    local name=$1
114
115
    if is_indexer_running $name; then
116
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
117
118
        DAEMONOPTS="--name=$name-koha-indexer \
119
            --errlog=/var/log/koha/$name/indexer-error.log \
120
            --stdout=/var/log/koha/$name/indexer.log \
121
            --output=/var/log/koha/$name/indexer-output.log \
122
            --verbose=1 --respawn --delay=30 \
123
            --user=$name-koha.$name-koha"
124
125
        log_daemon_msg "Stopping Koha indexing daemon for $name"
126
127
        if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then
128
            log_end_msg 0
129
        else
130
            log_end_msg 1
131
        fi
132
    else
133
        log_daemon_msg "Error: Indexer not running for $name"
134
        log_end_msg 1
135
    fi
136
}
137
138
set_action()
139
{
140
    if [ "$op" = "" ]; then
141
        op=$1
142
    else
143
        die "Error: only one action can be specified."
144
    fi
145
}
146
147
op=""
148
quiet="no"
149
150
# Read command line parameters
151
while [ $# -gt 0 ]; do
152
153
    case "$1" in
154
        -h|--help)
155
            usage ; exit 0 ;;
156
        -q|--quiet)
157
            quiet="yes"
158
            shift ;;
159
        --start)
160
            set_action "start"
161
            shift ;;
162
        --stop)
163
            set_action "stop"
164
            shift ;;
165
        --restart)
166
            set_action "restart"
167
            shift ;;
168
        -*)
169
            die "Error: invalid option switch ($1)" ;;
170
        *)
171
            # We expect the remaining stuff are the instance names
172
            break ;;
173
    esac
174
175
done
176
177
# Check if an alternate indexer has been set
178
if [ -z $ALTERNATE_INDEXER_DAEMON ]; then
179
    INDEXER_DAEMON="$ALTERNATE_INDEXER_DAEMON"
180
else
181
    # We default to rebuild_zebra.pl if no alternate indexer set
182
    INDEXER_DAEMON="${KOHA_HOME}/bin/migration_tools/rebuild_zebra.pl"
183
fi
184
185
if [ $INDEXER_TIMEOUT -lt 1 ]; then
186
    # Something's wrong, default to 5 seconds
187
    INDEXER_TIMEOUT=5
188
fi
189
190
if [ -z $INDEXER_PARAMS ]; then
191
    # Default to the parameters required by rebuild_zebra.pl
192
    INDEXER_PARAMS="-daemon -x -sleep $INDEXER_TIMEOUT"
193
fi
194
195
if [ -z $PERL5LIB ]; then
196
    PERL5LIB="/usr/share/koha/lib"
197
fi
198
199
export PERL5LIB
200
201
if [ $# -gt 0 ]; then
202
    # We have at least one instance name
203
    for name in "$@"; do
204
205
        if is_instance $name; then
206
207
            case $op in
208
                "start")
209
                    start_indexer $name
210
                    ;;
211
                "stop")
212
                    stop_indexer $name
213
                    ;;
214
                "restart")
215
                    restart_indexer $name
216
                    ;;
217
            esac
218
219
        else
220
            if [ "$quiet" = "no" ]; then
221
                log_daemon_msg "Error: Invalid instance name $name"
222
                log_end_msg 1
223
            fi
224
        fi
225
226
    done
227
else
228
    if [ "$quiet" = "no" ]; then
229
        warn "Error: you must provide at least one instance name"
230
    fi
231
fi
232
233
exit 0

Return to bug 8773