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