Bug 22857: (QA follow-up) Cosmetic changes: typo, whitespace
[koha.git] / debian / koha-common.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          koha-common
4 # Required-Start:    $remote_fs memcached
5 # Required-Stop:     $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Start required services for each Koha instance
9 # Description:       For each enabled Koha instance on this host,
10 #                    if enabled, start:
11 #                      - a Zebra server (using koha-zebra)
12 #                      - a Plack server (using koha-plack)
13 #                      - a SIP server   (using koha-sip)
14 #                      - a Z3950 server (using koha-z3950-responder)
15 ### END INIT INFO
16
17 # Author: Lars Wirzenius <lars@catalyst.net.nz>
18
19 # Do NOT "set -e"
20
21 # PATH should only include /usr/* if it runs after the mountnfs.sh script
22 PATH=/sbin:/usr/sbin:/bin:/usr/bin
23 DESC="Koha ILS"
24 NAME="koha-common"
25 SCRIPTNAME=/etc/init.d/$NAME
26
27 # Exit if the package is not installed
28 [ -x /usr/sbin/koha-zebra ] || exit 0
29
30 # Read configuration variable file if it is present
31 if [ -r /etc/default/$NAME ]; then
32     # Debian / Ubuntu
33     . /etc/default/$NAME
34 elif [ -r /etc/sysconfig/$NAME ]; then
35     # RedHat / SuSE
36     . /etc/sysconfig/$NAME
37 fi
38
39 # Load the VERBOSE setting and other rcS variables
40 . /lib/init/vars.sh
41
42 # Define LSB log_* functions.
43 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
44 . /lib/lsb/init-functions
45
46 # include helper functions
47 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
48     . "/usr/share/koha/bin/koha-functions.sh"
49 else
50     echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
51     exit 1
52 fi
53
54 #
55 # Function that starts the daemon/service
56 #
57 do_start()
58 {
59     # We insure all required directories exist, including disabled ones.
60     koha-create-dirs $(koha-list)
61     koha-zebra --start $(koha-list --enabled)
62     koha-sip   --start $(koha-list --enabled --sip)
63     koha-plack --start $(koha-list --enabled --plack)
64     koha-z3950-responder --start --quiet $(koha-list --enabled --z3950)
65
66     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
67         koha-indexer --start --quiet $(koha-list --enabled)
68     fi
69 }
70
71 #
72 # Function that stops the daemon/service
73 #
74 do_stop()
75 {
76     # We stop everything, including disabled ones.
77     koha-zebra --stop $(koha-list) || true
78     koha-sip   --stop $(koha-list --sip)
79     koha-plack --stop --quiet $(koha-list --enabled --plack)
80     koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950)
81
82     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
83         koha-indexer --stop --quiet $(koha-list --enabled)
84     fi
85 }
86
87 #
88 # Function that sends a SIGHUP to the daemon/service
89 #
90 do_reload() {
91     koha-zebra --restart $(koha-list --enabled)
92     koha-sip   --restart $(koha-list --enabled --sip)
93     koha-plack --restart --quiet $(koha-list --enabled --plack)
94     koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950)
95
96     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
97         koha-indexer --restart --quiet $(koha-list --enabled)
98     fi
99 }
100
101 #
102 # Function that shows the status of the zebrasrv daemon for
103 # enabled instances
104 #
105 zebra_status()
106 {
107     for instance in $(koha-list --enabled); do
108
109         log_daemon_msg "Zebra server running for instance $instance"
110
111         if is_zebra_running $instance ; then
112             log_end_msg 0
113         else
114             log_end_msg 1
115         fi
116     done
117 }
118
119 #
120 # Function that shows the status of the SIP server daemon for
121 # enabled instances
122 #
123 sip_status()
124 {
125     for instance in $(koha-list --enabled --sip); do
126
127         log_daemon_msg "SIP server running for instance $instance"
128
129         if is_sip_running $instance ; then
130             log_end_msg 0
131         else
132             log_end_msg 1
133         fi
134     done
135 }
136
137 #
138 # Function that shows the status of the Plack server daemon for
139 # enabled instances
140 #
141 plack_status()
142 {
143     for instance in $(koha-list --enabled --plack); do
144
145         log_daemon_msg "Plack server running for instance ${instance}"
146
147         if is_plack_running $instance ; then
148             log_end_msg 0
149         else
150             log_end_msg 1
151         fi
152     done
153 }
154
155 #
156 # Function that shows the status of the Z39.50/SRU server daemon for
157 # enabled instances
158 #
159 z3950_status()
160 {
161     for instance in $(koha-list --enabled --z3950); do
162
163         log_daemon_msg "Z39.50/SRU daemon running for instance ${instance}"
164
165         if is_z3950_running $instance ; then
166             log_end_msg 0
167         else
168             log_end_msg 1
169         fi
170     done
171 }
172
173 case "$1" in
174   start)
175         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
176         do_start
177         case "$?" in
178                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
179                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
180         esac
181         ;;
182   stop)
183         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
184         do_stop
185         case "$?" in
186                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
187                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
188         esac
189         ;;
190   restart|force-reload)
191         #
192         # If the "reload" option is implemented then remove the
193         # 'force-reload' alias
194         #
195         log_daemon_msg "Restarting $DESC" "$NAME"
196         do_stop
197         case "$?" in
198           0)
199                 do_start
200                 case "$?" in
201                         0) log_end_msg 0 ;;
202                         *) log_end_msg 1 ;; # Failed to start
203                 esac
204                 ;;
205           *)
206                 # Failed to stop
207                 log_end_msg 1
208                 ;;
209         esac
210         ;;
211   status)
212         zebra_status
213         sip_status
214         plack_status
215         z3950_status
216         ;;
217   *)
218     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
219         exit 3
220         ;;
221 esac
222
223 :