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

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

Return to bug 19962