3 # koha-sip - Manage SIP server for Koha instances
4 # Copyright 2019 Theke Solutions
5 # Copyright 2012 Catalyst IT, Ltd
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.
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.
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/>.
22 .
/lib
/lsb
/init-functions
24 # Read configuration variable file if it is present
25 [ -r /etc
/default
/koha-common
] && .
/etc
/default
/koha-common
27 # include helper functions
28 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
29 .
"/usr/share/koha/bin/koha-functions.sh"
31 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
37 local scriptname
=$
(basename $0)
42 This script lets you manage the SIP server for your Koha instances.
45 $scriptname [--start|--stop|--restart] instancename1 [instancename2...]
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
62 _check_and_fix_perms
$name
64 if ! is_sip_running
$name; then
66 adjust_paths_dev_install
$name
67 export KOHA_HOME PERL5LIB
69 if [ "$DEV_INSTALL" = "" ]; then
75 DAEMONOPTS
="--name=${name}-koha-sip \
76 --errlog=/var/log/koha/${name}/sip-error.log \
77 --stdout=/var/log/koha/${name}/sip.log \
78 --output=/var/log/koha/${name}/sip-output.log \
82 --pidfiles=/var/run/koha/${name} \
83 --user=${name}-koha.${name}-koha"
85 SIP_PARAMS
="$LIBDIR/C4/SIP/SIPServer.pm \
86 /etc/koha/sites/${name}/SIPconfig.xml"
88 [ "$verbose" != "no" ] && \
89 log_daemon_msg
"Starting SIP server for ${name}"
91 if daemon
$DAEMONOPTS -- perl
$SIP_PARAMS; then
92 ([ "$verbose" != "no" ] && \
93 log_end_msg
0) ||
return 0
95 ([ "$verbose" != "no" ] && \
96 log_end_msg
1) ||
return 1
99 if [ "$verbose" != "no" ]; then
100 log_daemon_msg
"Warning: SIP server already running for ${name}"
112 if is_sip_running
$name; then
114 DAEMONOPTS
="--name=${name}-koha-sip \
115 --errlog=/var/log/koha/${name}/sip-error.log \
116 --stdout=/var/log/koha/${name}/sip.log \
117 --output=/var/log/koha/${name}/sip-output.log \
121 --pidfiles=/var/run/koha/${name} \
122 --user=${name}-koha.${name}-koha"
124 [ "$verbose" != "no" ] && \
125 log_daemon_msg
"Stopping SIP server for ${name}"
127 if daemon
$DAEMONOPTS --stop; then
128 ([ "$verbose" != "no" ] && \
129 log_end_msg
0) ||
return 0
131 ([ "$verbose" != "no" ] && \
132 log_end_msg
1) ||
return 1
135 if [ "$verbose" != "no" ]; then
136 log_daemon_msg
"Warning: SIP server not running for ${name}"
148 if is_sip_running
${name}; then
150 [ "$verbose" != "no" ] && noLF
=""
151 echo $noLF `stop_sip ${name}`
154 while is_sip_running
${name}; do
156 if [ $MAX_ITERATION -lt $i ]; then
162 echo $noLF `start_sip ${name}`
164 if [ "$verbose" != "no" ]; then
165 log_daemon_msg
"Warning: SIP server not running for ${name}"
177 if is_sip_running
${name}; then
178 log_daemon_msg
"SIP server running for ${name}"
181 log_daemon_msg
"SIP server not running for ${name}"
190 sipfile
=/etc
/koha
/sites
/${name}/SIPconfig.xml
192 if is_sip_enabled
${name}; then
193 echo "Warning: SIP server already enabled for ${name}"
195 echo "Enabling SIP server for ${name} - edit ${sipfile} to configure"
196 cp -v /etc
/koha
/SIPconfig.xml
${sipfile}
197 chown
${name}-koha:${name}-koha ${sipfile}
202 _check_and_fix_perms
()
206 local files
="/var/log/koha/${name}/sip-error.log \
207 /var/log/koha/${name}/sip.log \
208 /var/log/koha/$name/sip-output.log"
212 if [ ! -e "${file}" ]; then
215 chown
"${name}-koha":"${name}-koha" ${file}
221 if [ "$op" = "" ]; then
224 die "Error
: only one action can be specified.
"
231 # Backwards compatible with old koha-*-sip scripts
232 # TODO: Remove once there's consensus to remove the legacy scripts
233 used_script_name=$(basename $0)
235 if [ "$used_script_name" != "koha-sip
" ]; then
236 warn "Deprecated
script used
(${used_script_name})"
238 case "$used_script_name" in
240 set_action "start
" ;;
244 set_action "enable" ;;
249 # / Backwards compatible handling code
251 # Read command line parameters
252 while [ $# -gt 0 ]; do
276 die "Error
: invalid option switch
($1)" ;;
278 # We expect the remaining stuff are the instance names
284 if [ $# -gt 0 ]; then
285 # We have at least one instance name
288 if is_instance $name; then
290 export KOHA_CONF="/etc
/koha
/sites
/$name/koha-conf.xml
"
310 if [ "$verbose" != "no
" ]; then
311 log_daemon_msg "Error
: Invalid instance name
$name"
318 if [ "$verbose" != "no
" ]; then
319 warn "Error
: you must provide
at least one instance name
"