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

(-)a/debian/koha-common.init (+20 lines)
Lines 60-65 do_start() Link Here
60
    koha-zebra --start $(koha-list --enabled)
60
    koha-zebra --start $(koha-list --enabled)
61
    koha-start-sip $(koha-list --enabled)
61
    koha-start-sip $(koha-list --enabled)
62
    koha-plack --start $(koha-list --enabled --plack)
62
    koha-plack --start $(koha-list --enabled --plack)
63
    koha-z3950-responder --start $(koha-list --enabled --z3950)
63
64
64
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
65
    if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
65
        koha-indexer --start --quiet $(koha-list --enabled)
66
        koha-indexer --start --quiet $(koha-list --enabled)
Lines 149-154 plack_status() Link Here
149
    done
150
    done
150
}
151
}
151
152
153
#
154
# Function that shows the status of the Z39.50/SRU server daemon for
155
# enabled instances
156
#
157
z3950_status()
158
{
159
    for instance in $(koha-list --enabled --z3950); do
160
161
        log_daemon_msg "Z39.50/SRU daemon running for instance ${instance}"
162
163
        if is_z3950_running $instance ; then
164
            log_end_msg 0
165
        else
166
            log_end_msg 1
167
        fi
168
    done
169
}
170
152
case "$1" in
171
case "$1" in
153
  start)
172
  start)
154
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
173
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
Lines 191-196 case "$1" in Link Here
191
        zebra_status
210
        zebra_status
192
        sip_status
211
        sip_status
193
        plack_status
212
        plack_status
213
        z3950_status
194
        ;;
214
        ;;
195
  *)
215
  *)
196
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
216
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
(-)a/debian/scripts/koha-create (-2 / +3 lines)
Lines 55-62 Options: Link Here
55
                            values are cs, en (default), es, fr, gr, nb, ru and uk.
55
                            values are cs, en (default), es, fr, gr, nb, ru and uk.
56
  --memcached-servers str   Set a comma-separated list of host:port memcached servers.
56
  --memcached-servers str   Set a comma-separated list of host:port memcached servers.
57
  --memcached-prefix str    Set the desired prefix for the instance memcached namespace.
57
  --memcached-prefix str    Set the desired prefix for the instance memcached namespace.
58
  --enable-sru              Enable the Z39.50/SRU server (default: disabled).
58
  --enable-sru              Enable the Z39.50/SRU server in Zebra search engine 
59
  --sru-port                Specifiy a TCP port number for the Z39.50/SRU server
59
                            (default: disabled).
60
  --sru-port                Specify a TCP port number for Zebra's Z39.50/SRU server
60
                            to listen on. (default: 7090).
61
                            to listen on. (default: 7090).
61
  --defaultsql some.sql     Specify a default SQL file to be loaded on the DB.
62
  --defaultsql some.sql     Specify a default SQL file to be loaded on the DB.
62
  --configfile cfg_file     Specify an alternate config file for reading default values.
63
  --configfile cfg_file     Specify an alternate config file for reading default values.
(-)a/debian/scripts/koha-functions.sh (+23 lines)
Lines 216-221 is_plack_running() Link Here
216
    fi
216
    fi
217
}
217
}
218
218
219
is_z3950_enabled()
220
{
221
    local instancename=$1
222
223
    if [ -e /etc/koha/sites/$instancename/z3950/config.xml ]; then
224
        return 0
225
    else
226
        return 1
227
    fi
228
}
229
230
is_z3950_running()
231
{
232
    local instancename=$1
233
234
    if start-stop-daemon --pidfile "/var/run/koha/${instancename}/z3950-responder.pid" \
235
            --status ; then
236
        return 0
237
    else
238
        return 1
239
    fi
240
}
241
219
adjust_paths_dev_install()
242
adjust_paths_dev_install()
220
{
243
{
221
# Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by
244
# Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by
(-)a/debian/scripts/koha-list (-1 / +42 lines)
Lines 39-44 show_instances() Link Here
39
              if instance_filter_email       $instance $show_email && \
39
              if instance_filter_email       $instance $show_email && \
40
                 instance_filter_letsencrypt $instance $show_letsencrypt && \
40
                 instance_filter_letsencrypt $instance $show_letsencrypt && \
41
                 instance_filter_plack       $instance $show_plack && \
41
                 instance_filter_plack       $instance $show_plack && \
42
                 instance_filter_z3950       $instance $show_z3950 && \
42
                 instance_filter_sip         $instance $show_sip; then
43
                 instance_filter_sip         $instance $show_sip; then
43
                    echo $instance
44
                    echo $instance
44
              fi ;;
45
              fi ;;
Lines 47-52 show_instances() Link Here
47
                  if instance_filter_email       $instance $show_email && \
48
                  if instance_filter_email       $instance $show_email && \
48
                     instance_filter_letsencrypt $instance $show_letsencrypt && \
49
                     instance_filter_letsencrypt $instance $show_letsencrypt && \
49
                     instance_filter_plack       $instance $show_plack && \
50
                     instance_filter_plack       $instance $show_plack && \
51
                     instance_filter_z3950       $instance $show_z3950 && \
50
                     instance_filter_sip         $instance $show_sip; then
52
                     instance_filter_sip         $instance $show_sip; then
51
                      echo $instance
53
                      echo $instance
52
                  fi
54
                  fi
Lines 56-61 show_instances() Link Here
56
                  if instance_filter_email       $instance $show_email && \
58
                  if instance_filter_email       $instance $show_email && \
57
                     instance_filter_letsencrypt $instance $show_letsencrypt && \
59
                     instance_filter_letsencrypt $instance $show_letsencrypt && \
58
                     instance_filter_plack       $instance $show_plack && \
60
                     instance_filter_plack       $instance $show_plack && \
61
                     instance_filter_z3950       $instance $show_z3950 && \
59
                     instance_filter_sip         $instance $show_sip; then
62
                     instance_filter_sip         $instance $show_sip; then
60
                      echo $instance
63
                      echo $instance
61
                  fi
64
                  fi
Lines 153-158 instance_filter_email() Link Here
153
    return 1
156
    return 1
154
}
157
}
155
158
159
instance_filter_z3950()
160
{
161
    local instancename=$1
162
    local show_z3950=$2;
163
164
    case $show_z3950 in
165
        "all")
166
            return 0 ;;
167
        "enabled")
168
            if is_z3950_enabled $instancename; then
169
                return 0
170
            fi ;;
171
        "disabled")
172
            if ! is_z3950_enabled $instancename; then
173
                return 0
174
            fi ;;
175
    esac
176
177
    # Didn't match any criteria
178
    return 1
179
}
180
156
set_show()
181
set_show()
157
{
182
{
158
    local show_param=$1
183
    local show_param=$1
Lines 208-213 set_show_sip() Link Here
208
    fi
233
    fi
209
}
234
}
210
235
236
set_show_z3950()
237
{
238
    local z3950_param=$1
239
240
    if [ "$show_z3950" = "all" ]; then
241
        show_z3950=$z3950_param
242
    else
243
        die "Error: --z3950 and --noz3950 are mutually exclusive."
244
    fi
245
}
246
211
usage()
247
usage()
212
{
248
{
213
    local scriptname=$0
249
    local scriptname=$0
Lines 228-233 Options: Link Here
228
    --noplack       Show instances with Plack disabled
264
    --noplack       Show instances with Plack disabled
229
    --letsencrypt   Show instances with letsencrypt enabled
265
    --letsencrypt   Show instances with letsencrypt enabled
230
    --noletsencrypt Show instances with letsencrypt disabled
266
    --noletsencrypt Show instances with letsencrypt disabled
267
    --z3950         Show instances with Z39.50/SRU enabled
268
    --noz3950       Show instances with Z39.50/SRU disabled
231
    --help | -h     Show this help
269
    --help | -h     Show this help
232
270
233
The filtering options can be combined, and you probably want to do this
271
The filtering options can be combined, and you probably want to do this
Lines 240-247 show_email="all" Link Here
240
show_sip="all"
278
show_sip="all"
241
show_plack="all"
279
show_plack="all"
242
show_letsencrypt="all"
280
show_letsencrypt="all"
281
show_z3950="all"
243
282
244
args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt -o h -n $0 -- "$@")
283
args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt,z3950,noz3950 -o h -n $0 -- "$@")
245
set -- $args
284
set -- $args
246
285
247
while [ ! -z "$1" ]
286
while [ ! -z "$1" ]
Lines 256-261 do Link Here
256
      --noplack) set_show_plack "disabled" ;;
295
      --noplack) set_show_plack "disabled" ;;
257
  --letsencrypt) set_show_letsencrypt "enabled" ;;
296
  --letsencrypt) set_show_letsencrypt "enabled" ;;
258
--noletsencrypt) set_show_letsencrypt "disabled" ;;
297
--noletsencrypt) set_show_letsencrypt "disabled" ;;
298
        --z3950) set_show_z3950 "enabled" ;;
299
      --noz3950) set_show_z3950 "disabled" ;;
259
      --enabled) set_show "enabled" ;;
300
      --enabled) set_show "enabled" ;;
260
     --disabled) set_show "disabled" ;;
301
     --disabled) set_show "disabled" ;;
261
              *) break;;
302
              *) break;;
(-)a/debian/scripts/koha-z3950-responder (+354 lines)
Line 0 Link Here
1
#!/bin/bash
2
#
3
# Copyright 2015 Theke Solutions
4
# Copyright 2016 Koha-Suomi
5
# Copyright 2018 The National Library of Finland, University of Helsinki
6
#
7
# This file is part of Koha.
8
#
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
13
#
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22
set -e
23
24
. /lib/lsb/init-functions
25
26
# Read configuration variable file if it is present
27
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
28
29
# include helper functions
30
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
31
    . "/usr/share/koha/bin/koha-functions.sh"
32
else
33
    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
34
    exit 1
35
fi
36
37
usage()
38
{
39
    local scriptname=$(basename $0)
40
41
    cat <<EOF
42
$scriptname
43
44
This script lets you manage the Z39.50/SRU daemons for your Koha instances.
45
46
Usage:
47
$scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...]
48
$scriptname --enable|--disable instancename1 [instancename2]
49
$scriptname -h|--help
50
51
    --start               Start the Z39.50/SRU daemon for the specified instances
52
    --stop                Stop the Z39.50/SRU daemon for the specified instances
53
    --restart             Restart the Z39.50/SRU daemon for the specified instances
54
    --enable              Enable Z39.50/SRU for the specified instances
55
    --disable             Disable Z39.50/SRU for the specified instances
56
    --debugger            Enable running Z39.50/SRU in debug mode
57
    --debugger-key        Specify the key the IDE is expecting
58
    --debugger-location   Specify the host:port for your debugger tool (defaults
59
                          to localhost:9000)
60
    --debugger-path       Specify the path for the debugger library
61
    --quiet|-q            Make the script quiet about non existent instance names
62
                          (useful for calling from another scripts).
63
    --help|-h             Display this help message
64
65
EOF
66
}
67
68
start_z3950()
69
{
70
    local instancename=$1
71
72
    local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid"
73
    local NAME="${instancename}-koha-z3950-responder"
74
    local CONFIGDIR="/etc/koha/z3950"
75
76
    if [ -e "/etc/koha/sites/${instancename}/z3950/config.xml" ]; then
77
        # pick instance-specific config dir
78
        CONFIGDIR="/etc/koha/sites/${instancename}/z3950"
79
    fi # else stick with the default one
80
81
    _check_and_fix_perms $instancename
82
83
    instance_user="${instancename}-koha"
84
85
    daemonize="-D -d ${instancename}-koha-z3950"
86
    logging="-l /var/log/koha/${instancename}/z3950.log"
87
88
    if [ "$DEV_INSTALL" = "1" ]; then
89
        LIBDIR=$KOHA_HOME
90
    else
91
        LIBDIR=$KOHA_HOME/lib
92
    fi
93
94
    Z3950RESPONDER="/usr/bin/perl $LIBDIR/misc/z3950_responder.pl"
95
    if [ "$debug_mode" = "yes" ]; then
96
        if [ "$DEV_INSTALL" = "1" ]; then
97
            warn "Not a dev install, disabling debug mode"
98
        else
99
            environment="development"
100
            daemonize=""
101
            logging="" # remote debugger takes care
102
            Z3950RESPONDER="/usr/bin/perl -d ${LIBDIR}/misc/z3950_responder.pl"
103
        fi
104
    fi
105
106
    Z3950OPTS="-c ${CONFIGDIR} \
107
               -u ${instance_user} \
108
               -p ${PIDFILE} ${daemonize} ${logging}"
109
110
    if ! is_z3950_running ${instancename}; then
111
        export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml"
112
113
        log_daemon_msg "Starting Z39.50/SRU daemon for ${instancename}"
114
115
        # Change to the instance's user dir
116
        current_dir=$(pwd)
117
        eval cd ~$instance_user
118
119
        if ${Z3950RESPONDER} ${Z3950OPTS}; then
120
            log_end_msg 0
121
        else
122
            log_end_msg 1
123
        fi
124
        # Go back to the original dir
125
        cd "$current_dir"
126
127
    else
128
        log_daemon_msg "Error: Z39.50/SRU already running for ${instancename}"
129
        log_end_msg 1
130
    fi
131
}
132
133
stop_z3950()
134
{
135
    local instancename=$1
136
137
    local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid"
138
139
    if is_z3950_running ${instancename}; then
140
141
        log_daemon_msg "Stopping Z39.50/SRU daemon for ${instancename}"
142
143
        if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then
144
            log_end_msg 0
145
        else
146
            log_end_msg 1
147
        fi
148
    else
149
        log_daemon_msg "Error: Z39.50/SRU not running for ${instancename}"
150
        log_end_msg 1
151
    fi
152
}
153
154
restart_z3950()
155
{
156
    local instancename=$1
157
158
    local PIDFILE="/var/run/koha/${instancename}/z3950.pid"
159
160
    if is_z3950_running ${instancename}; then
161
162
        log_daemon_msg "Restarting Z39.50/SRU daemon for ${instancename}"
163
164
        if stop_z3950 $instancename && start_z3950 $instancename; then
165
            log_end_msg 0
166
        else
167
            log_end_msg 1
168
        fi
169
    else
170
        log_daemon_msg "Error: Z39.50/SRU not running for ${instancename}"
171
        log_end_msg 1
172
    fi
173
}
174
175
enable_z3950()
176
{
177
    local instancename=$1
178
179
    if [ ! -e /etc/koha/sites/${instancename}/koha-conf.xml ] ;
180
    then
181
        echo "No such instance: ${instancename}" > /dev/stderr
182
        return 1
183
    fi 
184
      
185
    local configdir=/etc/koha/sites/${instancename}/z3950
186
    if [ -e ${configdir}/config.xml ]
187
    then
188
        [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already enabled for $name"
189
        return 1
190
    fi
191
192
    if [ ! -e ${configdir} ]
193
    then
194
        mkdir ${configdir}
195
    fi
196
    cp /etc/koha/z3950/* ${configdir}/
197
    chown ${name}-koha:${name}-koha ${configdir}/*
198
    chmod 600 ${configdir}/*
199
200
    [ "${quiet}" != "yes" ] && warn "Z39.50/SRU enabled for $name - edit files in ${configdir} to configure"
201
    return 0
202
}
203
204
disable_z3950()
205
{
206
    local instancename=$1
207
208
    if is_z3950_enabled $instancename; then
209
        local configdir=/etc/koha/sites/${instancename}/z3950
210
        mv ${configdir} ${configdir}.`date +%F_%T`
211
        [ "${quiet}" != "yes" ] && warn "Z39.50/SRU disabled for ${instancename}"
212
        return 0
213
    else
214
        [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already disabled for ${instancename}"
215
        return 1
216
    fi
217
}
218
219
_check_and_fix_perms()
220
{
221
    local instance=$1
222
223
    local files="/var/log/koha/${instance}/z3950.log"
224
225
    for file in ${files}
226
    do
227
        if [ ! -e "${file}" ]; then
228
            touch ${file}
229
        fi
230
        chown "${instance}-koha":"${instance}-koha" ${file}
231
    done
232
}
233
234
set_action()
235
{
236
    if [ "$op" = "" ]; then
237
        op=$1
238
    else
239
        die "Error: only one action can be specified."
240
    fi
241
}
242
243
op=""
244
quiet="no"
245
debug_mode="no"
246
debugger_key=""
247
debugger_location="localhost:9000"
248
debugger_path=""
249
250
# Read command line parameters
251
while [ $# -gt 0 ]; do
252
253
    case "$1" in
254
        -h|--help)
255
            usage ; exit 0 ;;
256
        -q|--quiet)
257
            quiet="yes"
258
            shift ;;
259
        --start)
260
            set_action "start"
261
            shift ;;
262
        --stop)
263
            set_action "stop"
264
            shift ;;
265
        --restart)
266
            set_action "restart"
267
            shift ;;
268
        --enable)
269
            set_action "enable"
270
            shift ;;
271
        --disable)
272
            set_action "disable"
273
            shift ;;
274
        --debugger)
275
            debug_mode="yes"
276
            shift ;;
277
        --debugger-key)
278
            debugger_key="$2"
279
            shift 2 ;;
280
        --debugger-location)
281
            debugger_location="$2"
282
            shift 2 ;;
283
        --debugger-path)
284
            debugger_path="$2"
285
            shift 2 ;;
286
        -*)
287
            die "Error: invalid option switch ($1)" ;;
288
        *)
289
            # We expect the remaining stuff are the instance names
290
            break ;;
291
    esac
292
293
done
294
295
if [ $# -gt 0 ]; then
296
    # We have at least one instance name
297
    for name in "$@"; do
298
299
        if is_instance $name; then
300
301
            adjust_paths_dev_install $name
302
            export DEV_INSTALL
303
            export KOHA_HOME
304
            PERL5LIB=$PERL5LIB:$KOHA_HOME/installer:$KOHA_HOME/lib/installer
305
            # If debug mode is enabled, add the debugger lib path
306
            # to PERL5LIB if appropriate
307
            if [ "$debug_mode" = "yes" ]; then
308
                if [ "$debugger_path" != "" ]; then
309
                    PERL5LIB="${debugger_path}":$PERL5LIB
310
                fi
311
                export PERL5DB="BEGIN { require q(${debugger_path}/perl5db.pl) }"
312
                export PERLDB_OPTS="RemotePort=${debugger_location} async=1 LogFile=/var/log/koha/${name}/z3950-debug.log"
313
                export DBGP_IDEKEY=${debugger_key}
314
                export PERL5OPT="-d"
315
            fi
316
317
            export PERL5LIB
318
319
            case $op in
320
                "start")
321
                    start_z3950 $name
322
                    ;;
323
                "stop")
324
                    stop_z3950 $name
325
                    ;;
326
                "restart")
327
                    restart_z3950 $name
328
                    ;;
329
                "enable")
330
                    enable_z3950 $name
331
                    ;;
332
                "disable")
333
                    disable_z3950 $name
334
                    ;;
335
                *)
336
                    usage
337
                    ;;
338
            esac
339
340
        else
341
            if [ "$quiet" = "no" ]; then
342
                log_daemon_msg "Error: Invalid instance name $name"
343
                log_end_msg 1
344
            fi
345
        fi
346
347
    done
348
else
349
    if [ "$quiet" = "no" ]; then
350
        warn "Error: you must provide at least one instance name"
351
    fi
352
fi
353
354
exit 0
(-)a/etc/z3950/config.xml (+1 lines)
Lines 1-4 Link Here
1
<yazgfs>
1
<yazgfs>
2
  <listen id="public">tcp:@:2100</listen>
2
  <server>
3
  <server>
3
    <cql2rpn>pqf.properties</cql2rpn>
4
    <cql2rpn>pqf.properties</cql2rpn>
4
    <explain xmlns="http://explain.z3950.org/dtd/2.0/">
5
    <explain xmlns="http://explain.z3950.org/dtd/2.0/">
(-)a/misc/z3950_responder.pl (-6 lines)
Lines 156-166 GetOptions( Link Here
156
pod2usage(1) if $help;
156
pod2usage(1) if $help;
157
pod2usage( -verbose => 2 ) if $man;
157
pod2usage( -verbose => 2 ) if $man;
158
158
159
if (!@ARGV || $ARGV[-1] =~ /^-/) {
160
    # No bind address specified. Use @:2100 by default.
161
    push(@ARGV, '@:2100');
162
}
163
164
# If config_dir is not defined, default to z3950 under the Koha config directory
159
# If config_dir is not defined, default to z3950 under the Koha config directory
165
if (!$config_dir) {
160
if (!$config_dir) {
166
    (undef, $config_dir) = fileparse(Koha::Config->guess_koha_conf);
161
    (undef, $config_dir) = fileparse(Koha::Config->guess_koha_conf);
167
- 

Return to bug 13937