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

(-)a/debian/koha-common.install (+1 lines)
Lines 37-40 debian/scripts/koha-zebra usr/sbin Link Here
37
debian/scripts/koha-start-sip               usr/sbin
37
debian/scripts/koha-start-sip               usr/sbin
38
debian/scripts/koha-stop-sip                usr/sbin
38
debian/scripts/koha-stop-sip                usr/sbin
39
debian/scripts/koha-enable-sip              usr/sbin
39
debian/scripts/koha-enable-sip              usr/sbin
40
debian/scripts/koha-sip                     usr/sbin
40
debian/tmp_docbook/*.8                      usr/share/man/man8
41
debian/tmp_docbook/*.8                      usr/share/man/man8
(-)a/debian/scripts/koha-functions.sh (+14 lines)
Lines 157-162 is_sitemap_enabled() Link Here
157
    fi
157
    fi
158
}
158
}
159
159
160
is_sip_running()
161
{
162
    local instancename=$1
163
164
    if daemon --name="$instancename-koha-sip" \
165
            --pidfiles="/var/run/koha/$instancename/" \
166
            --user="$instancename-koha.$instancename-koha" \
167
            --running ; then
168
        return 0
169
    else
170
        return 1
171
    fi
172
}
173
160
is_zebra_running()
174
is_zebra_running()
161
{
175
{
162
    local instancename=$1
176
    local instancename=$1
(-)a/debian/scripts/koha-sip (-1 / +308 lines)
Line 0 Link Here
0
- 
1
#!/bin/bash
2
3
# koha-sip - Manage SIP server for Koha instances
4
#              Copyright 2019 Theke Solutions
5
#              Copyright 2012 Catalyst IT, Ltd
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
set -e
21
22
. /lib/lsb/init-functions
23
24
# Read configuration variable file if it is present
25
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
26
27
# include helper functions
28
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
29
    . "/usr/share/koha/bin/koha-functions.sh"
30
else
31
    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
32
    exit 1
33
fi
34
35
usage()
36
{
37
    local scriptname=$(basename $0)
38
39
    cat <<EOF
40
$scriptname
41
42
This script lets you manage the SIP server for your Koha instances.
43
44
Usage:
45
$scriptname [--start|--stop|--restart] instancename1 [instancename2...]
46
$scriptname -h|--help
47
48
    --start               Start the SIP server for the specified instance(s)
49
    --stop                Stop the SIP server for the specified instance(s)
50
    --restart             Restart the SIP server for the specified instance(s)
51
    --status              Show the status of the SIP server for the specified instance(s)
52
    --verbose|-v          Display progress and actions messages
53
    --help|-h             Display this help message
54
55
EOF
56
}
57
58
start_sip()
59
{
60
    local name=$1
61
62
    _check_and_fix_perms $name
63
64
    if ! is_sip_running $name; then
65
66
        adjust_paths_dev_install $name
67
        export KOHA_CONF PERL5LIB
68
        if [ "$DEV_INSTALL" = "" ]; then
69
            LIBDIR=$KOHA_HOME/lib
70
        else
71
            LIBDIR=$KOHA_HOME
72
        fi
73
74
        DAEMONOPTS="--name=${name}-koha-sip \
75
                    --errlog=/var/log/koha/${name}/sip-error.log \
76
                    --stdout=/var/log/koha/${name}/sip.log \
77
                    --output=/var/log/koha/${name}/sip-output.log \
78
                    --verbose=1 \
79
                    --respawn \
80
                    --delay=30 \
81
                    --pidfiles=/var/run/koha/${name} \
82
                    --user=${name}-koha.${name}-koha"
83
84
        SIP_PARAMS="$LIBDIR/C4/SIP/SIPServer.pm \
85
                    /etc/koha/sites/${name}/SIPconfig.xml"
86
87
        [ "$verbose" != "no" ] && \
88
            log_daemon_msg "Starting Koha Zebra daemon for ${name}"
89
90
        if daemon $DAEMONOPTS -- perl $SIP_PARAMS; then
91
            ([ "$verbose" != "no" ] && \
92
                log_end_msg 0) || return 0
93
        else
94
            ([ "$verbose" != "no" ] && \
95
                log_end_msg 1) || return 1
96
        fi
97
    else
98
        if [ "$verbose" != "no" ]; then
99
            log_daemon_msg "Warning: SIP server already running for ${name}"
100
            log_end_msg 0
101
        else
102
            return 0
103
        fi
104
    fi
105
}
106
107
stop_sip()
108
{
109
    local name=$1
110
111
    if is_sip_running $name; then
112
113
        DAEMONOPTS="--name=${name}-koha-sip \
114
                    --errlog=/var/log/koha/${name}/sip-error.log \
115
                    --stdout=/var/log/koha/${name}/sip.log \
116
                    --output=/var/log/koha/${name}/sip-output.log \
117
                    --verbose=1 \
118
                    --respawn \
119
                    --delay=30 \
120
                    --pidfiles=/var/run/koha/${name} \
121
                    --user=${name}-koha.${name}-koha"
122
123
        [ "$verbose" != "no" ] && \
124
            log_daemon_msg "Stopping SIP server for ${name}"
125
126
        if daemon $DAEMONOPTS --stop; then
127
            ([ "$verbose" != "no" ] && \
128
                log_end_msg 0) || return 0
129
        else
130
            ([ "$verbose" != "no" ] && \
131
                log_end_msg 1) || return 1
132
        fi
133
    else
134
        if [ "$verbose" != "no" ]; then
135
            log_daemon_msg "Warning: SIP server not running for ${name}"
136
            log_end_msg 0
137
        else
138
            return 0
139
        fi
140
    fi
141
}
142
143
restart_sip()
144
{
145
    local name=$1
146
147
    if is_sip_running ${name}; then
148
        local noLF="-n"
149
        [ "$verbose" != "no" ] && noLF=""
150
        echo $noLF `stop_sip ${name}`
151
        echo $noLF `start_sip ${name}`
152
    else
153
        if [ "$verbose" != "no" ]; then
154
            log_daemon_msg "Warning: SIP server not running for ${name}"
155
            log_end_msg 0
156
        else
157
            return 0
158
        fi
159
    fi
160
}
161
162
sip_status()
163
{
164
    local name=$1
165
166
    if is_sip_running ${name}; then
167
        log_daemon_msg "SIP server running for ${name}"
168
        log_end_msg 0
169
    else
170
        log_daemon_msg "SIP server not running for ${name}"
171
        log_end_msg 3
172
    fi
173
}
174
175
enable_sip()
176
{
177
    local name=$1
178
179
    sipfile=/etc/koha/sites/${name}/SIPconfig.xml
180
181
    if is_sip_enabled ${name}; then
182
        echo "Warning: SIP server already enabled for ${name}"
183
    else
184
        echo "Enabling SIP server for ${name} - edit ${sipfile} to configure"
185
        cp -v /etc/koha/SIPconfig.xml ${sipfile}
186
        chown ${name}-koha:${name}-koha ${sipfile}
187
        chmod 600 ${sipfile}
188
    fi
189
}
190
191
_check_and_fix_perms()
192
{
193
    local name=$1
194
195
    local files="/var/log/koha/${name}/sip-error.log \
196
                 /var/log/koha/${name}/sip.log \
197
                 /var/log/koha/$name/sip-output.log"
198
199
    for file in ${files}
200
    do
201
        if [ ! -e "${file}" ]; then
202
            touch ${file}
203
        fi
204
        chown "${name}-koha":"${name}-koha" ${file}
205
    done
206
}
207
208
set_action()
209
{
210
    if [ "$op" = "" ]; then
211
        op=$1
212
    else
213
        die "Error: only one action can be specified."
214
    fi
215
}
216
217
op=""
218
verbose="no"
219
220
# Backwards compatible with old koha-*-sip scripts
221
# TODO: Remove once there's consensus to remove the legacy scripts
222
used_script_name=$(basename $0)
223
224
if [ "$used_script_name" != "koha-sip" ]; then
225
    warn "Deprecated script used (${used_script_name})"
226
227
    case "$used_script_name" in
228
        koha-start-sip)
229
            set_action "start" ;;
230
        koha-stop-sip)
231
            set_action "stop" ;;
232
        *)
233
            break ;;
234
    esac
235
fi
236
# / Backwards compatible handling code
237
238
# Read command line parameters
239
while [ $# -gt 0 ]; do
240
241
    case "$1" in
242
        -h|--help)
243
            usage ; exit 0 ;;
244
        -v|--verbose)
245
            verbose="yes"
246
            shift ;;
247
        --start)
248
            set_action "start"
249
            shift ;;
250
        --stop)
251
            set_action "stop"
252
            shift ;;
253
        --restart)
254
            set_action "restart"
255
            shift ;;
256
        --status)
257
            set_action "status"
258
            shift ;;
259
        --enable)
260
            set_action "enable"
261
            shift ;;
262
        -*)
263
            die "Error: invalid option switch ($1)" ;;
264
        *)
265
            # We expect the remaining stuff are the instance names
266
            break ;;
267
    esac
268
269
done
270
271
if [ $# -gt 0 ]; then
272
    # We have at least one instance name
273
    for name in "$@"; do
274
275
        if is_instance $name; then
276
277
            case $op in
278
                "start")
279
                    start_sip $name
280
                    ;;
281
                "stop")
282
                    stop_sip $name
283
                    ;;
284
                "restart")
285
                    restart_sip $name
286
                    ;;
287
                "status")
288
                    sip_status $name
289
                    ;;
290
                "enable")
291
                    enable_sip $name
292
            esac
293
294
        else
295
            if [ "$verbose" != "no" ]; then
296
                log_daemon_msg "Error: Invalid instance name $name"
297
                log_end_msg 1
298
            fi
299
        fi
300
301
    done
302
else
303
    if [ "$verbose" != "no" ]; then
304
        warn "Error: you must provide at least one instance name"
305
    fi
306
fi
307
308
exit 0

Return to bug 18562