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

(-)a/debian/docs/koha-common.xml (+8 lines)
Lines 138-144 Link Here
138
          <para>Manage the indexer daemon for named Koha instances.</para>
138
          <para>Manage the indexer daemon for named Koha instances.</para>
139
        </listitem>
139
        </listitem>
140
      </varlistentry>
140
      </varlistentry>
141
142
      <varlistentry>
143
        <term><option>koha-worker</option></term>
144
        <listitem>
145
          <para>Manage the worker daemon for named Koha instances.</para>
146
        </listitem>
147
      </varlistentry>
141
    </variablelist>
148
    </variablelist>
149
142
    </refsect2>
150
    </refsect2>
143
151
144
    <refsect2>
152
    <refsect2>
(-)a/debian/koha-common.init (+3 lines)
Lines 62-67 do_start() Link Here
62
    koha-sip   --start $(koha-list --enabled --sip)
62
    koha-sip   --start $(koha-list --enabled --sip)
63
    koha-plack --start $(koha-list --enabled --plack)
63
    koha-plack --start $(koha-list --enabled --plack)
64
    koha-z3950-responder --start --quiet $(koha-list --enabled --z3950)
64
    koha-z3950-responder --start --quiet $(koha-list --enabled --z3950)
65
    koha-worker --start $(koha-list --enabled)
65
66
66
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
67
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
67
        koha-indexer --start --quiet $(koha-list --enabled)
68
        koha-indexer --start --quiet $(koha-list --enabled)
Lines 78-83 do_stop() Link Here
78
    koha-sip   --stop $(koha-list --sip)
79
    koha-sip   --stop $(koha-list --sip)
79
    koha-plack --stop --quiet $(koha-list --enabled --plack)
80
    koha-plack --stop --quiet $(koha-list --enabled --plack)
80
    koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950)
81
    koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950)
82
    koha-worker --stop --quiet $(koha-list --enabled)
81
83
82
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
84
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
83
        koha-indexer --stop --quiet $(koha-list --enabled)
85
        koha-indexer --stop --quiet $(koha-list --enabled)
Lines 92-97 do_reload() { Link Here
92
    koha-sip   --restart $(koha-list --enabled --sip)
94
    koha-sip   --restart $(koha-list --enabled --sip)
93
    koha-plack --restart --quiet $(koha-list --enabled --plack)
95
    koha-plack --restart --quiet $(koha-list --enabled --plack)
94
    koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950)
96
    koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950)
97
    koha-worker --restart --quiet $(koha-list --enabled)
95
98
96
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
99
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
97
        koha-indexer --restart --quiet $(koha-list --enabled)
100
        koha-indexer --restart --quiet $(koha-list --enabled)
(-)a/debian/scripts/koha-create (+3 lines)
Lines 752-757 then Link Here
752
    # Start Zebra.
752
    # Start Zebra.
753
    koha-zebra --start "$name"
753
    koha-zebra --start "$name"
754
754
755
    # Start worker
756
    koha-worker --start "$name"
757
755
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
758
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
756
        # Start Indexer daemon
759
        # Start Indexer daemon
757
        koha-indexer --start "$name"
760
        koha-indexer --start "$name"
(-)a/debian/scripts/koha-disable (+3 lines)
Lines 72-77 do Link Here
72
            if is_indexer_running $name; then
72
            if is_indexer_running $name; then
73
                koha-indexer --stop $name
73
                koha-indexer --stop $name
74
            fi
74
            fi
75
            if is_worker_running $name; then
76
                koha-worker --stop $name
77
            fi
75
        elif [ "$RET" = 2 ]; then
78
        elif [ "$RET" = 2 ]; then
76
            warn "Error: Apache configuration file not present for instance $name."
79
            warn "Error: Apache configuration file not present for instance $name."
77
        else
80
        else
(-)a/debian/scripts/koha-functions.sh (+14 lines)
Lines 199-204 is_indexer_running() Link Here
199
    fi
199
    fi
200
}
200
}
201
201
202
is_worker_running()
203
{
204
    local instancename=$1
205
206
    if daemon --name="$instancename-koha-worker" \
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_plack_enabled_opac()
216
is_plack_enabled_opac()
203
{
217
{
204
    local instancefile=$1
218
    local instancefile=$1
(-)a/debian/scripts/koha-remove (+4 lines)
Lines 81-86 eof Link Here
81
    if is_indexer_running $name; then
81
    if is_indexer_running $name; then
82
        koha-indexer --stop $name || /bin/true
82
        koha-indexer --stop $name || /bin/true
83
    fi
83
    fi
84
    # Stop the worker daemon if needed
85
    if is_worker_running $name; then
86
        koha-worker --stop $name || /bin/true
87
    fi
84
    # Stop the Plack server if needed
88
    # Stop the Plack server if needed
85
    if is_plack_running $name; then
89
    if is_plack_running $name; then
86
        koha-plack --stop $name || /bin/true
90
        koha-plack --stop $name || /bin/true
(-)a/debian/scripts/koha-worker (+242 lines)
Line 0 Link Here
1
#!/bin/bash
2
#
3
# Copyright 2020 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 worker daemon for your Koha instances.
41
42
Usage:
43
$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...]
44
$scriptname -h|--help
45
46
    --start               Start the worker daemon for the specified instances
47
    --stop                Stop the worker daemon for the specified instances
48
    --restart             Restart the worker daemon for the specified instances
49
    --status              Show the status of the worker 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_worker()
58
{
59
    local name=$1
60
61
    if ! is_worker_running $name; then
62
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
63
64
        DAEMONOPTS="--name=$name-koha-worker \
65
            --errlog=/var/log/koha/$name/worker-error.log \
66
            --stdout=/var/log/koha/$name/worker.log \
67
            --output=/var/log/koha/$name/worker-output.log \
68
            --pidfiles=/var/run/koha/$name/ \
69
            --verbose=1 --respawn --delay=30 \
70
            --user=$name-koha.$name-koha"
71
72
        log_daemon_msg "Starting Koha worker daemon for $name"
73
74
        if daemon $DAEMONOPTS -- $worker_DAEMON; then
75
            log_end_msg 0
76
        else
77
            log_end_msg 1
78
        fi
79
    else
80
        log_daemon_msg "Error: worker already running for $name"
81
        log_end_msg 1
82
    fi
83
}
84
85
stop_worker()
86
{
87
    local name=$1
88
89
    if is_worker_running $name; then
90
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
91
92
        DAEMONOPTS="--name=$name-koha-worker \
93
            --errlog=/var/log/koha/$name/worker-error.log \
94
            --stdout=/var/log/koha/$name/worker.log \
95
            --output=/var/log/koha/$name/worker-output.log \
96
            --pidfiles=/var/run/koha/$name/ \
97
            --verbose=1 --respawn --delay=30 \
98
            --user=$name-koha.$name-koha"
99
100
        log_daemon_msg "Stopping Koha worker daemon for $name"
101
102
        if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then
103
            log_end_msg 0
104
        else
105
            log_end_msg 1
106
        fi
107
    else
108
        log_daemon_msg "Error: worker not running for $name"
109
        log_end_msg 1
110
    fi
111
}
112
113
restart_worker()
114
{
115
    local name=$1
116
117
    if is_worker_running $name; then
118
        export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
119
120
        DAEMONOPTS="--name=$name-koha-worker \
121
            --errlog=/var/log/koha/$name/worker-error.log \
122
            --stdout=/var/log/koha/$name/worker.log \
123
            --output=/var/log/koha/$name/worker-output.log \
124
            --pidfiles=/var/run/koha/$name/ \
125
            --verbose=1 --respawn --delay=30 \
126
            --user=$name-koha.$name-koha"
127
128
        log_daemon_msg "Restarting Koha worker daemon for $name"
129
130
        if daemon $DAEMONOPTS --restart -- $worker_DAEMON; then
131
            log_end_msg 0
132
        else
133
            log_end_msg 1
134
        fi
135
    else
136
        log_daemon_msg "Error: worker not running for $name"
137
        log_end_msg 1
138
    fi
139
}
140
141
worker_status()
142
{
143
    local name=$1
144
145
    if is_worker_running ${name}; then
146
        log_daemon_msg "worker running for ${name}"
147
        log_end_msg 0
148
    else
149
        log_daemon_msg "worker not running for ${name}"
150
        log_end_msg 3
151
    fi
152
}
153
154
set_action()
155
{
156
    if [ "$op" = "" ]; then
157
        op=$1
158
    else
159
        die "Error: only one action can be specified."
160
    fi
161
}
162
163
op=""
164
quiet="no"
165
166
# Read command line parameters
167
while [ $# -gt 0 ]; do
168
169
    case "$1" in
170
        -h|--help)
171
            usage ; exit 0 ;;
172
        -q|--quiet)
173
            quiet="yes"
174
            shift ;;
175
        --start)
176
            set_action "start"
177
            shift ;;
178
        --stop)
179
            set_action "stop"
180
            shift ;;
181
        --restart)
182
            set_action "restart"
183
            shift ;;
184
        --status)
185
            set_action "status"
186
            shift ;;
187
        -*)
188
            die "Error: invalid option switch ($1)" ;;
189
        *)
190
            # We expect the remaining stuff are the instance names
191
            break ;;
192
    esac
193
194
done
195
196
# Optionally use alternative paths for a dev install
197
adjust_paths_dev_install $1
198
199
if [ "$DEV_INSTALL" = "" ]; then
200
    worker_DAEMON="${KOHA_HOME}/bin/background_jobs_worker.pl"
201
else
202
    worker_DAEMON="${KOHA_HOME}/misc/background_jobs_worker.pl"
203
fi
204
205
# PERL5LIB has been read from etc/default
206
export PERL5LIB
207
208
if [ $# -gt 0 ]; then
209
    # We have at least one instance name
210
    for name in "$@"; do
211
212
        if is_instance $name; then
213
214
            case $op in
215
                "start")
216
                    start_worker $name
217
                    ;;
218
                "stop")
219
                    stop_worker $name
220
                    ;;
221
                "restart")
222
                    restart_worker $name
223
                    ;;
224
                "status")
225
                    worker_status $name
226
            esac
227
228
        else
229
            if [ "$quiet" = "no" ]; then
230
                log_daemon_msg "Error: Invalid instance name $name"
231
                log_end_msg 1
232
            fi
233
        fi
234
235
    done
236
else
237
    if [ "$quiet" = "no" ]; then
238
        warn "Error: you must provide at least one instance name"
239
    fi
240
fi
241
242
exit 0
(-)a/misc/background_jobs_worker.pl (-1 / +52 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# 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
# Koha is distributed in the hope that it will be useful, but
11
# 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 Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use JSON qw( encode_json decode_json );
20
21
use Koha::BackgroundJob::BatchUpdateBiblio;
22
use Koha::BackgroundJob;
23
24
my $conn = Koha::BackgroundJob->connect;
25
26
my $channel = $conn->open_channel();
27
28
my $job_type = 'batch_biblio_record_modification';
29
$channel->declare_queue(
30
    queue => $job_type,
31
    durable => 1,
32
);
33
34
$channel->qos(prefetch_count => 1,);
35
36
$channel->consume(
37
    on_consume => sub {
38
        my $var = shift;
39
        my $body = $var->{body}->{payload};
40
        say " [x] Received $body";
41
42
        my $args = decode_json( $body );
43
44
        Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel);
45
        say " [x] Done";
46
    },
47
    no_ack => 0,
48
);
49
50
warn "waiting forever";
51
# Wait forever
52
AnyEvent->condvar->recv;

Return to bug 22417