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