allow collections deep inside git
[jelmer/calypso.git] / calypso-init
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          calypso
4 # Required-Start:    $network $remote_fs
5 # Required-Stop:     $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: CalDAV/CardDAV server
9 # Description:       Calendar and Contact server over WebDAV
10 #                    using the CalDAV and CardDAV protocols
11 ### END INIT INFO
12
13 # Author: Keith Packard <keithp@keithp.com>
14 # Author: Joe Nahmias <jello@debian.org>
15
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH=/sbin:/usr/sbin:/bin:/usr/bin
18 DESC="Calypso CalDAV Server"
19 NAME=calypso
20 DAEMON=/usr/sbin/$NAME
21 PIDFILE=/var/run/$NAME.pid
22 SCRIPTNAME=/etc/init.d/$NAME
23
24 # Exit if the package is not installed
25 [ -x "$DAEMON" ] || exit 0
26
27 # Read configuration variable file if it is present
28 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
29
30 # Load the VERBOSE setting and other rcS variables
31 . /lib/init/vars.sh
32
33 # Define LSB log_* functions.
34 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
35 # and status_of_proc is working.
36 . /lib/lsb/init-functions
37
38 #
39 # Check whether daemon starting is enabled
40 #
41 check_start_daemon() {
42         if [ "$DISABLE_CALPYSO" = "yes" ]; then
43                 [ "$VERBOSE" != no ] && \
44                         log_warning_msg "Not starting calypso, disabled via /etc/default/calypso"
45                 return 1
46         else
47                 return 0
48         fi
49 }
50
51 #
52 # Function that starts the daemon/service
53 #
54 do_start()
55 {
56         # Return
57         #   0 if daemon has been started
58         #   1 if daemon was already running
59         #   2 if daemon could not be started
60         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
61                 || return 1
62         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
63                 $CALYPSO_OPTS \
64                 || return 2
65         # Add code here, if necessary, that waits for the process to be ready
66         # to handle requests from services started subsequently which depend
67         # on this one.  As a last resort, sleep for some time.
68 }
69
70 #
71 # Function that stops the daemon/service
72 #
73 do_stop()
74 {
75         # Return
76         #   0 if daemon has been stopped
77         #   1 if daemon was already stopped
78         #   2 if daemon could not be stopped
79         #   other if a failure occurred
80         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
81         RETVAL="$?"
82         [ "$RETVAL" = 2 ] && return 2
83         # Wait for children to finish too if this is a daemon that forks
84         # and if the daemon is only ever run from this initscript.
85         # If the above conditions are not satisfied then add some other code
86         # that waits for the process to drop all resources that could be
87         # needed by services started subsequently.  A last resort is to
88         # sleep for some time.
89         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
90         [ "$?" = 2 ] && return 2
91         # Many daemons don't delete their pidfiles when they exit.
92         rm -f $PIDFILE
93         return "$RETVAL"
94 }
95
96 #
97 # Function that sends a SIGHUP to the daemon/service
98 #
99 do_reload() {
100         #
101         # If the daemon can reload its configuration without
102         # restarting (for example, when it is sent a SIGHUP),
103         # then implement that here.
104         #
105         start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
106         return 0
107 }
108
109 case "$1" in
110   start)
111         check_start_daemon || exit 0
112         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
113         do_start
114         case "$?" in
115                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
116                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
117         esac
118         ;;
119   stop)
120         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
121         do_stop
122         case "$?" in
123                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
124                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
125         esac
126         ;;
127   status)
128        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
129        ;;
130   #reload|force-reload)
131         #
132         # If do_reload() is not implemented then leave this commented out
133         # and leave 'force-reload' as an alias for 'restart'.
134         #
135         #log_daemon_msg "Reloading $DESC" "$NAME"
136         #do_reload
137         #log_end_msg $?
138         #;;
139   restart|force-reload)
140         #
141         # If the "reload" option is implemented then remove the
142         # 'force-reload' alias
143         #
144         log_daemon_msg "Restarting $DESC" "$NAME"
145         do_stop
146         case "$?" in
147           0|1)
148                 do_start
149                 case "$?" in
150                         0) log_end_msg 0 ;;
151                         1) log_end_msg 1 ;; # Old process is still running
152                         *) log_end_msg 1 ;; # Failed to start
153                 esac
154                 ;;
155           *)
156                 # Failed to stop
157                 log_end_msg 1
158                 ;;
159         esac
160         ;;
161   *)
162         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
163         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
164         exit 3
165         ;;
166 esac
167
168 :