Bug 10617 - koha-common init script cleanup
[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
54 #
55 # Function that stops the daemon/service
56 #
57 do_stop()
58 {
59     # We stop everything, including disabled ones.
60     koha-stop-zebra $(koha-list) || true
61     koha-stop-sip $(koha-list) || true
62 }
63
64 #
65 # Function that sends a SIGHUP to the daemon/service
66 #
67 do_reload() {
68     koha-restart-zebra $(koha-list --enabled)
69     koha-stop-sip $(koha-list) || true
70     koha-start-sip $(koha-list --enabled)
71 }
72
73 case "$1" in
74   start)
75         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
76         do_start
77         case "$?" in
78                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
79                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
80         esac
81         ;;
82   stop)
83         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
84         do_stop
85         case "$?" in
86                 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
87                 *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
88         esac
89         ;;
90   restart|force-reload)
91         #
92         # If the "reload" option is implemented then remove the
93         # 'force-reload' alias
94         #
95         log_daemon_msg "Restarting $DESC" "$NAME"
96         do_stop
97         case "$?" in
98           0)
99                 do_start
100                 case "$?" in
101                         0) log_end_msg 0 ;;
102                         *) log_end_msg 1 ;; # Failed to start
103                 esac
104                 ;;
105           *)
106                 # Failed to stop
107                 log_end_msg 1
108                 ;;
109         esac
110         ;;
111 # TODO: Implement this. It should check every daemon is running
112 #  status)
113 #        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
114 #        ;;
115   *)
116     #echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
117     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
118         exit 3
119         ;;
120 esac
121
122 :