Bug 15128 - DBRev 15128
[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 # include helper functions
44 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
45     . "/usr/share/koha/bin/koha-functions.sh"
46 else
47     echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
48     exit 1
49 fi
50
51 #
52 # Function that starts the daemon/service
53 #
54 do_start()
55 {
56     # We insure all required directories exist, including disabled ones.
57     koha-create-dirs $(koha-list)
58     koha-start-zebra $(koha-list --enabled)
59     koha-start-sip $(koha-list --enabled)
60     koha-plack --start --quiet $(koha-list --enabled --plack)
61
62     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
63         koha-indexer --start --quiet $(koha-list --enabled)
64     fi
65 }
66
67 #
68 # Function that stops the daemon/service
69 #
70 do_stop()
71 {
72     # We stop everything, including disabled ones.
73     koha-stop-zebra $(koha-list) || true
74     koha-stop-sip $(koha-list) || true
75     koha-plack --stop --quiet $(koha-list --enabled --plack)
76
77     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
78         koha-indexer --stop --quiet $(koha-list --enabled)
79     fi
80 }
81
82 #
83 # Function that sends a SIGHUP to the daemon/service
84 #
85 do_reload() {
86     koha-restart-zebra $(koha-list --enabled)
87     koha-stop-sip $(koha-list) || true
88     koha-start-sip $(koha-list --enabled)
89     koha-plack --restart --quiet $(koha-list --enabled --plack)
90
91     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
92         koha-indexer --restart --quiet $(koha-list --enabled)
93     fi
94 }
95
96 #
97 # Function that shows the status of the zebrasrv daemon for
98 # enabled instances
99 #
100 zebra_status()
101 {
102     for instance in $(koha-list --enabled); do
103
104         log_daemon_msg "Zebra server running for instance $instance"
105
106         if is_zebra_running $instance ; then
107             log_end_msg 0
108         else
109             log_end_msg 1
110         fi
111     done
112 }
113
114 #
115 # Function that shows the status of the SIP server daemon for
116 # enabled instances
117 #
118 sip_status()
119 {
120     for instance in $(koha-list --enabled --sip); do
121
122         log_daemon_msg "SIP server running for instance $instance"
123
124         if is_sip_running $instance ; then
125             log_end_msg 0
126         else
127             log_end_msg 1
128         fi
129     done
130 }
131
132 #
133 # Function that shows the status of the Plack server daemon for
134 # enabled instances
135 #
136 plack_status()
137 {
138     for instance in $(koha-list --enabled --plack); do
139
140         log_daemon_msg "Plack server running for instance ${instance}"
141
142         if is_plack_running $instance ; then
143             log_end_msg 0
144         else
145             log_end_msg 1
146         fi
147     done
148 }
149
150 case "$1" in
151   start)
152         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
153         do_start
154         case "$?" in
155                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
156                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
157         esac
158         ;;
159   stop)
160         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
161         do_stop
162         case "$?" in
163                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
164                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
165         esac
166         ;;
167   restart|force-reload)
168         #
169         # If the "reload" option is implemented then remove the
170         # 'force-reload' alias
171         #
172         log_daemon_msg "Restarting $DESC" "$NAME"
173         do_stop
174         case "$?" in
175           0)
176                 do_start
177                 case "$?" in
178                         0) log_end_msg 0 ;;
179                         *) log_end_msg 1 ;; # Failed to start
180                 esac
181                 ;;
182           *)
183                 # Failed to stop
184                 log_end_msg 1
185                 ;;
186         esac
187         ;;
188   status)
189         zebra_status
190         sip_status
191         plack_status
192         ;;
193   *)
194     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
195         exit 3
196         ;;
197 esac
198
199 :