* buildpackages can create deb source tarballs now.
[citadel.git] / webcit / debian / webcit.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          skeleton
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: Example initscript
9 # Description:       This file should be used to construct scripts to be
10 #                    placed in /etc/init.d.
11 ### END INIT INFO
12
13 # Author: Foo Bar <foobar@baz.org>
14 #
15 # Please remove the "Author" lines above and replace them
16 # with your own name if you copy and modify this script.
17
18 # Do NOT "set -e"
19
20 # PATH should only include /usr/* if it runs after the mountnfs.sh script
21 RUNDIR=/var/run/webcit
22 PATH=/sbin:/usr/sbin:/bin:/usr/bin
23 DESC="Citadel Groupware Webserver "
24 NAME=webserver
25 DAEMON=/usr/sbin/$NAME
26 DAEMON_ARGS=""
27 PIDFILE=$RUNDIR/$NAME.pid
28 SCRIPTNAME=/etc/init.d/webcit
29 SENDCOMMAND=/usr/sbin/sendcommand
30 DEFAULT=/etc/default/webcit
31 LOGDIR=/var/log/webcit/
32
33
34 unset LANG
35 unset LANGUAGE
36 unset LC_ALL
37 unset LOCALE
38 # Exit if the package is not installed
39 [ -x "$DAEMON" ] || exit 0
40
41 # Read configuration variable file if it is present
42 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
43
44 MODERN=
45
46 # Load the VERBOSE setting and other rcS variables
47 if test -f /lib/init/vars.sh ; then
48     . /lib/init/vars.sh
49     MODERN=1
50 fi
51
52 # Define LSB log_* functions.
53 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
54 if test -f /lib/lsb/init-functions; then
55     . /lib/lsb/init-functions
56     MODERN=1
57 fi
58
59 if test -f $DEFAULT; then
60   . $DEFAULT
61 fi
62
63 #
64 # Function that starts the daemon/service
65 #
66 do_start()
67 {
68     #1: -p flag
69     #1: port
70     #2: ssl
71
72         # for ubuntu: check our volatile dirs.
73         if test ! -d $RUNDIR; then
74             mkdir -p $RUNDIR
75         fi
76
77         if test ! -d $LOGDIR; then
78             mkdir -p $LOGDIR
79         fi
80
81
82
83         # are we disabled?
84         if test "$1" -lt "0"; then
85             return 0
86         fi
87
88         # Return
89         #   0 if daemon has been started
90         #   1 if daemon was already running
91         #   2 if daemon could not be started
92         if $DAEMON -d$PIDFILE.$1 \
93             -p$@ -t$LOGDIR/access.${1}.log ; then
94             return 0
95         else
96             return 2
97         fi
98         # Add code here, if necessary, that waits for the process to be ready
99         # to handle requests from services started subsequently which depend
100         # on this one.  As a last resort, sleep for some time.
101 }
102
103 #
104 # Function that stops the daemon/service
105 #
106 do_stop()
107 {
108         # Return
109         #   0 if daemon has been stopped
110         #   1 if daemon was already stopped
111         #   2 if daemon could not be stopped
112         #   other if a failure occurred
113
114         for i in $PIDFILE.*; do if test -f $i; then
115             kill `cat $i`
116             rm -f $i
117         fi; done
118
119         #while test -d /proc/`cat $PIDFILE`; do
120         #    /usr/bin/printf  '.'
121         #    /bin/sleep 1
122         #done
123  
124         #start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
125         #RETVAL="$?"
126         #[ "$RETVAL" = 2 ] && return 2
127         # Wait for children to finish too if this is a daemon that forks
128         # and if the daemon is only ever run from this initscript.
129         # If the above conditions are not satisfied then add some other code
130         # that waits for the process to drop all resources that could be
131         # needed by services started subsequently.  A last resort is to
132         # sleep for some time.
133         #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
134         #[ "$?" = 2 ] && return 2
135         # Many daemons don't delete their pidfiles when they exit.
136         # rm -f $PIDFILE
137 }
138
139 #
140 # Function that sends a SIGHUP to the daemon/service
141 #
142 do_reload() {
143         #
144         # If the daemon can reload its configuration without
145         # restarting (for example, when it is sent a SIGHUP),
146         # then implement that here.
147         #
148 #       start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
149         do_stop
150         do_start
151         return 0
152 }
153
154 case "$1" in
155   start)
156         if test -n "$MODERN"; then
157         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
158         else
159             echo "Starting $DESC" "$NAME"
160         fi
161
162         do_start $WEBCIT_HTTP_PORT $WEBCIT_CITADEL_IP $WEBCIT_CITADEL_PORT
163         do_start $WEBCIT_HTTPS_PORT $WEBCIT_CITADEL_IP $WEBCIT_CITADEL_PORT -s
164
165         if test -n "$MODERN"; then
166             case "$?" in
167                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
168                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
169             esac
170         fi
171         ;;
172   stop)
173         if test -n "$MODERN"; then
174             [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
175         else
176             echo "Stopping $DESC" "$NAME"
177         fi
178         do_stop
179         if test -n "$MODERN"; then
180             case "$?" in
181                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
182                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
183             esac
184         fi
185         ;;
186   #reload|force-reload)
187         #
188         # If do_reload() is not implemented then leave this commented out
189         # and leave 'force-reload' as an alias for 'restart'.
190         #
191         #log_daemon_msg "Reloading $DESC" "$NAME"
192         #do_reload
193         #log_end_msg $?
194         #;;
195   restart|force-reload)
196         #
197         # If the "reload" option is implemented then remove the
198         # 'force-reload' alias
199         #
200         if test -n "$MODERN"; then
201         log_daemon_msg "Restarting $DESC" "$NAME"
202         else
203             echo "Restarting $DESC" "$NAME"
204         fi
205
206         do_stop
207
208         if test -n "$MODERN"; then
209             case "$?" in
210                 0|1)
211                     do_start
212                     case "$?" in
213                         0) log_end_msg 0 ;;
214                         1) log_end_msg 1 ;; # Old process is still running
215                         *) log_end_msg 1 ;; # Failed to start
216                     esac
217                     ;;
218                 *)
219                 # Failed to stop
220                     log_end_msg 1
221                     ;;
222             esac
223         fi
224         ;;
225   *)
226         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
227         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
228         exit 3
229         ;;
230 esac
231
232 :