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