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