Bug 29881: libdbd-sqlite2-perl is unavailable on deb12 (koha-common wont install)
[koha.git] / debian / koha-core.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          koha-core
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-core"
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 ##    koha-worker --start $(koha-list --enabled)
66
67     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
68         koha-indexer --start --quiet $(koha-list --enabled)
69     fi
70 }
71
72 #
73 # Function that stops the daemon/service
74 #
75 do_stop()
76 {
77     # We stop everything, including disabled ones.
78 ##    koha-zebra --stop $(koha-list) || true
79 ##    koha-sip   --stop $(koha-list --sip)
80 ##    koha-plack --stop --quiet $(koha-list --enabled --plack)
81 ##    koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950)
82 ##    koha-worker --stop --quiet $(koha-list --enabled)
83
84     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
85         koha-indexer --stop --quiet $(koha-list --enabled)
86     fi
87 }
88
89 #
90 # Function that sends a SIGHUP to the daemon/service
91 #
92 do_reload() {
93 ##    koha-zebra --restart $(koha-list --enabled)
94 ##    koha-sip   --restart $(koha-list --enabled --sip)
95 ##    koha-plack --restart --quiet $(koha-list --enabled --plack)
96 ##    koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950)
97 ##    koha-worker --restart --quiet $(koha-list --enabled)
98
99     if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
100         koha-indexer --restart --quiet $(koha-list --enabled)
101     fi
102 }
103
104 #
105 # Function that shows the status of the zebrasrv daemon for
106 # enabled instances
107 #
108 zebra_status()
109 {
110     for instance in $(koha-list --enabled); do
111
112         log_daemon_msg "Zebra server running for instance $instance"
113
114         if is_zebra_running $instance ; then
115             log_end_msg 0
116         else
117             log_end_msg 1
118         fi
119     done
120 }
121
122 #
123 # Function that shows the status of the SIP server daemon for
124 # enabled instances
125 #
126 sip_status()
127 {
128     for instance in $(koha-list --enabled --sip); do
129
130         log_daemon_msg "SIP server running for instance $instance"
131
132         if is_sip_running $instance ; then
133             log_end_msg 0
134         else
135             log_end_msg 1
136         fi
137     done
138 }
139
140 #
141 # Function that shows the status of the Plack server daemon for
142 # enabled instances
143 #
144 plack_status()
145 {
146     for instance in $(koha-list --enabled --plack); do
147
148         log_daemon_msg "Plack server running for instance ${instance}"
149
150         if is_plack_running $instance ; then
151             log_end_msg 0
152         else
153             log_end_msg 1
154         fi
155     done
156 }
157
158 #
159 # Function that shows the status of the Z39.50/SRU server daemon for
160 # enabled instances
161 #
162 z3950_status()
163 {
164     for instance in $(koha-list --enabled --z3950); do
165
166         log_daemon_msg "Z39.50/SRU daemon running for instance ${instance}"
167
168         if is_z3950_running $instance ; then
169             log_end_msg 0
170         else
171             log_end_msg 1
172         fi
173     done
174 }
175
176 case "$1" in
177   start)
178         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
179         do_start
180         case "$?" in
181                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
182                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
183         esac
184         ;;
185   stop)
186         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
187         do_stop
188         case "$?" in
189                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
190                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
191         esac
192         ;;
193   restart|force-reload)
194         #
195         # If the "reload" option is implemented then remove the
196         # 'force-reload' alias
197         #
198         log_daemon_msg "Restarting $DESC" "$NAME"
199         do_stop
200         case "$?" in
201           0)
202                 do_start
203                 case "$?" in
204                         0) log_end_msg 0 ;;
205                         *) log_end_msg 1 ;; # Failed to start
206                 esac
207                 ;;
208           *)
209                 # Failed to stop
210                 log_end_msg 1
211                 ;;
212         esac
213         ;;
214   status)
215         zebra_status
216         sip_status
217         plack_status
218         z3950_status
219         ;;
220   *)
221     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
222         exit 3
223         ;;
224 esac
225
226 :