* cleanup init scripts
[citadel.git] / citadel / debian / citadel.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          citadel-server
4 # Required-Start:    $local_fs $remote_fs
5 # Required-Stop:     $local_fs $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Citadel initscript
9 ### END INIT INFO
10
11 # Author: Wilfried Goesgens <citadel@outgesourced.org>
12 RUNDIR=/var/run/citadel
13 PATH=/sbin:/usr/sbin:/bin:/usr/bin
14 DESC="Citadel Groupware "
15 NAME=citserver
16 DAEMON=/usr/sbin/$NAME
17 DAEMON_ARGS=" -d -x3 -lmail -t/dev/null"
18 PIDFILE=$RUNDIR/$NAME.pid
19 SCRIPTNAME=/etc/init.d/citadel
20 SENDCOMMAND=/usr/sbin/sendcommand
21
22
23 # Exit if the package is not installed
24 [ -x "$DAEMON" ] || exit 0
25
26 # Read configuration variable file if it is present
27 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
28
29 # check if we 've got a newer system, so we can do fancy colors and so on.
30 MODERN=
31
32 # Load the VERBOSE setting and other rcS variables
33 if test -f /lib/init/vars.sh ; then
34     . /lib/init/vars.sh
35     MODERN=1
36 fi
37 # Define LSB log_* functions.
38 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
39 if test -f /lib/lsb/init-functions; then
40     . /lib/lsb/init-functions
41     MODERN=1
42 fi
43
44 #
45 # Function that starts the daemon/service
46 #
47 do_start()
48 {
49         # for ubuntu: check our volatile dirs.
50         if test ! -d $RUNDIR; then
51             mkdir -p $RUNDIR
52         fi
53         # Return
54         #   0 if daemon has been started
55         #   1 if daemon was already running
56         #   2 if daemon could not be started
57         if $DAEMON \
58                 $DAEMON_ARGS ; then
59             return 0
60         else
61             return 2
62         fi
63 }
64
65 #
66 # Function that stops the daemon/service
67 #
68 do_stop()
69 {
70         # Return
71         #   0 if daemon has been stopped
72         #   1 if daemon was already stopped
73         #   2 if daemon could not be stopped
74         #   other if a failure occurred
75         if $SENDCOMMAND "DOWN" >/dev/null 2>&1 ; then
76             rm -f $PIDFILE
77
78             while test -S /var/run/citadel/citadel.socket; do 
79                 sleep 1
80                 echo -n "."
81             done
82                 return 0
83         else
84             rm -f $PIDFILE
85             return 2
86         fi
87
88 }
89
90 #
91 # Function that sends a SIGHUP to the daemon/service
92 #
93 do_reload() {
94         do_stop
95         do_start
96         return 0
97 }
98
99 case "$1" in
100   start)
101         if test -n "$MODERN"; then
102             [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
103         else
104             echo "Starting $DESC" "$NAME"
105         fi
106
107         do_start
108         if test -n "$MODERN"; then
109             case "$?" in
110                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
111                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
112             esac
113         fi
114         ;;
115   stop)
116         if test -n "$MODERN"; then
117             [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
118         else
119             echo "Stopping $DESC" "$NAME"
120         fi
121         do_stop
122         if test -n "$MODERN"; then
123             case "$?" in
124                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
125                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
126             esac
127         fi
128         ;;
129   restart|force-reload)
130         if test -n "$MODERN"; then
131             log_daemon_msg "Restarting $DESC" "$NAME"
132         else
133             echo "Restarting $DESC" "$NAME"
134         fi
135
136         do_stop
137
138         if test -n "$MODERN"; then
139             case "$?" in
140                 0|1)
141                     do_start
142                     case "$?" in
143                         0) log_end_msg 0 ;;
144                         1) log_end_msg 1 ;; # Old process is still running
145                         *) log_end_msg 1 ;; # Failed to start
146                     esac
147                     ;;
148                 *)
149                 # Failed to stop
150                     log_end_msg 1
151                     ;;
152             esac
153         else
154             do_start
155         fi
156         ;;
157   *)
158         echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
159         exit 3
160         ;;
161 esac
162
163 :