Bug 11479: Remove experimental given/when keywords
[koha.git] / debian / koha-common.init
blob1ba591dfd302aaf7fa6285b01936449ad0893ff1
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: koha-common
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: Start Zebra server for each Koha instance
9 # Description: For each enabled Koha instance on this host,
10 # as listed by "koha-list --enabled", start a Zebra
11 # server (using koha-start-zebra).
12 ### END INIT INFO
14 # Author: Lars Wirzenius <lars@catalyst.net.nz>
16 # Do NOT "set -e"
18 # PATH should only include /usr/* if it runs after the mountnfs.sh script
19 PATH=/sbin:/usr/sbin:/bin:/usr/bin
20 DESC="Koha ILS"
21 NAME="koha-common"
22 SCRIPTNAME=/etc/init.d/$NAME
24 # Exit if the package is not installed
25 [ -x /usr/sbin/koha-start-zebra ] || exit 0
27 # Read configuration variable file if it is present
28 if [ -r /etc/default/$NAME ]; then
29 # Debian / Ubuntu
30 . /etc/default/$NAME
31 elif [ -r /etc/sysconfig/$NAME ]; then
32 # RedHat / SuSE
33 . /etc/sysconfig/$NAME
36 # Load the VERBOSE setting and other rcS variables
37 . /lib/init/vars.sh
39 # Define LSB log_* functions.
40 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
41 . /lib/lsb/init-functions
44 # Function that starts the daemon/service
46 do_start()
48 # We insure all required directories exist, including disabled ones.
49 koha-create-dirs $(koha-list)
50 koha-start-zebra $(koha-list --enabled)
51 koha-start-sip $(koha-list --enabled)
55 # Function that stops the daemon/service
57 do_stop()
59 # We stop everything, including disabled ones.
60 koha-stop-zebra $(koha-list) || true
61 koha-stop-sip $(koha-list) || true
65 # Function that sends a SIGHUP to the daemon/service
67 do_reload() {
68 koha-restart-zebra $(koha-list --enabled)
69 koha-stop-sip $(koha-list) || true
70 koha-start-sip $(koha-list --enabled)
74 # Function that checks zebrasrv is running for the specified instance
76 is_zebra_running()
78 local instancename=$1
80 if daemon --name="$instancename-koha-zebra" \
81 --user="$instancename-koha.$instancename-koha" \
82 --running ; then
83 return 0
84 else
85 return 1
90 # Function that checks SIP server is running for the specified instance
92 is_sip_running()
94 local instancename=$1
96 if daemon --name="$instancename-koha-sip" \
97 --pidfiles="/var/run/koha/$instancename" \
98 --user="$instancename-koha.$instancename-koha" \
99 --running ; then
100 return 0
101 else
102 return 1
107 # Function that shows the status of the zebrasrv daemon for
108 # enabled instances
110 zebra_status()
112 for instance in $(koha-list --enabled); do
114 log_daemon_msg "Zebra server running for instace $instance"
116 if is_zebra_running $instance ; then
117 log_end_msg 0
118 else
119 log_end_msg 1
121 done
125 # Function that shows the status of the SIP server daemon for
126 # enabled instances
128 sip_status()
130 for instance in $(koha-list --enabled --sip); do
132 log_daemon_msg "SIP server running for instace $instance"
134 if is_sip_running $instance ; then
135 log_end_msg 0
136 else
137 log_end_msg 1
139 done
142 case "$1" in
143 start)
144 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
145 do_start
146 case "$?" in
147 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
148 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
149 esac
151 stop)
152 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
153 do_stop
154 case "$?" in
155 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
156 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
157 esac
159 restart|force-reload)
161 # If the "reload" option is implemented then remove the
162 # 'force-reload' alias
164 log_daemon_msg "Restarting $DESC" "$NAME"
165 do_stop
166 case "$?" in
168 do_start
169 case "$?" in
170 0) log_end_msg 0 ;;
171 *) log_end_msg 1 ;; # Failed to start
172 esac
175 # Failed to stop
176 log_end_msg 1
178 esac
180 status)
181 zebra_status
182 sip_status
185 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
186 exit 3
188 esac