Bug 14056: Small punctuation error in description for deleting a holiday
[koha.git] / debian / koha-common.init
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
13
14 # Author: Lars Wirzenius <lars@catalyst.net.nz>
15
16 # Do NOT "set -e"
17
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
23
24 # Exit if the package is not installed
25 [ -x /usr/sbin/koha-start-zebra ] || exit 0
26
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
34 fi
35
36 # Load the VERBOSE setting and other rcS variables
37 . /lib/init/vars.sh
38
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
42
43 #
44 # Function that starts the daemon/service
45 #
46 do_start()
47 {
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)
52
53     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
54         koha-indexer --start --quiet $(koha-list --enabled)
55     fi
56 }
57
58 #
59 # Function that stops the daemon/service
60 #
61 do_stop()
62 {
63     # We stop everything, including disabled ones.
64     koha-stop-zebra $(koha-list) || true
65     koha-stop-sip $(koha-list) || true
66
67     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
68         koha-indexer --stop --quiet $(koha-list --enabled)
69     fi
70 }
71
72 #
73 # Function that sends a SIGHUP to the daemon/service
74 #
75 do_reload() {
76     koha-restart-zebra $(koha-list --enabled)
77     koha-stop-sip $(koha-list) || true
78     koha-start-sip $(koha-list --enabled)
79
80     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
81         koha-indexer --restart --quiet $(koha-list --enabled)
82     fi
83 }
84
85 #
86 # Function that checks zebrasrv is running for the specified instance
87 #
88 is_zebra_running()
89 {
90     local instancename=$1
91
92     if daemon --name="$instancename-koha-zebra" \
93             --user="$instancename-koha.$instancename-koha" \
94             --running ; then
95         return 0
96     else
97         return 1
98     fi
99 }
100
101 #
102 # Function that checks SIP server is running for the specified instance
103 #
104 is_sip_running()
105 {
106     local instancename=$1
107
108     if daemon --name="$instancename-koha-sip" \
109             --pidfiles="/var/run/koha/$instancename" \
110             --user="$instancename-koha.$instancename-koha" \
111             --running ; then
112         return 0
113     else
114         return 1
115     fi
116 }
117
118 #
119 # Function that shows the status of the zebrasrv daemon for
120 # enabled instances
121 #
122 zebra_status()
123 {
124     for instance in $(koha-list --enabled); do
125
126         log_daemon_msg "Zebra server running for instace $instance"
127
128         if is_zebra_running $instance ; then
129             log_end_msg 0
130         else
131             log_end_msg 1
132         fi
133     done
134 }
135
136 #
137 # Function that shows the status of the SIP server daemon for
138 # enabled instances
139 #
140 sip_status()
141 {
142     for instance in $(koha-list --enabled --sip); do
143
144         log_daemon_msg "SIP server running for instace $instance"
145
146         if is_sip_running $instance ; then
147             log_end_msg 0
148         else
149             log_end_msg 1
150         fi
151     done
152 }
153
154 case "$1" in
155   start)
156         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
157         do_start
158         case "$?" in
159                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
160                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
161         esac
162         ;;
163   stop)
164         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
165         do_stop
166         case "$?" in
167                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
168                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
169         esac
170         ;;
171   restart|force-reload)
172         #
173         # If the "reload" option is implemented then remove the
174         # 'force-reload' alias
175         #
176         log_daemon_msg "Restarting $DESC" "$NAME"
177         do_stop
178         case "$?" in
179           0)
180                 do_start
181                 case "$?" in
182                         0) log_end_msg 0 ;;
183                         *) log_end_msg 1 ;; # Failed to start
184                 esac
185                 ;;
186           *)
187                 # Failed to stop
188                 log_end_msg 1
189                 ;;
190         esac
191         ;;
192   status)
193         zebra_status
194         sip_status
195         ;;
196   *)
197     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
198         exit 3
199         ;;
200 esac
201
202 :