3e3521ba41f758cf7cfee67f7757c4f7e87a7590
[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         # are we disabled?
75         if test "$1" -lt "0"; then
76             return 0
77         fi
78
79         # Return
80         #   0 if daemon has been started
81         #   1 if daemon was already running
82         #   2 if daemon could not be started
83         if $DAEMON -D$PIDFILE.$1 \
84             -p$@ -t$LOGDIR/access.${1}.log ; then
85             return 0
86         else
87             return 2
88         fi
89 }
90
91 #
92 # Function that stops the daemon/service
93 #
94 do_stop()
95 {
96         for i in $PIDFILE.*; do if test -f $i; then
97             kill `cat $i`
98             rm -f $i
99         fi; done
100 }
101
102 do_reload() {
103         do_stop
104         do_start
105         return 0
106 }
107
108 case "$1" in
109   start)
110         if test -n "$MODERN"; then
111         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
112         else
113             echo "Starting $DESC" "$NAME"
114         fi
115
116         do_start $WEBCIT_HTTP_PORT $WEBCIT_CITADEL_IP $WEBCIT_CITADEL_PORT
117         do_start $WEBCIT_HTTPS_PORT $WEBCIT_CITADEL_IP $WEBCIT_CITADEL_PORT -s
118
119         if test -n "$MODERN"; then
120             case "$?" in
121                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
122                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
123             esac
124         fi
125         ;;
126   stop)
127         if test -n "$MODERN"; then
128             [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
129         else
130             echo "Stopping $DESC" "$NAME"
131         fi
132         do_stop
133         if test -n "$MODERN"; then
134             case "$?" in
135                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
136                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
137             esac
138         fi
139         ;;
140   restart|force-reload)
141         if test -n "$MODERN"; then
142         log_daemon_msg "Restarting $DESC" "$NAME"
143         else
144             echo "Restarting $DESC" "$NAME"
145         fi
146
147         do_stop
148
149         if test -n "$MODERN"; then
150             case "$?" in
151                 0|1)
152                     do_start
153                     case "$?" in
154                         0) log_end_msg 0 ;;
155                         1) log_end_msg 1 ;; # Old process is still running
156                         *) log_end_msg 1 ;; # Failed to start
157                     esac
158                     ;;
159                 *)
160                 # Failed to stop
161                     log_end_msg 1
162                     ;;
163             esac
164         else
165             do_start
166         fi
167         ;;
168   *)
169         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
170         exit 3
171         ;;
172 esac
173
174 :