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