* Fixed an error in the template that was causing the 'c_creataide' field to load...
[citadel.git] / citadel / debian / citadel.init
blob3bacf5ab05295ee85e505e8a8093df386f407f65
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: citadel
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: control citadel server start at boot time
9 # Description: control citadel server start at boot time
10 ### END INIT INFO
12 # Author: Wilfried Goesgens <citadel@outgesourced.org>
14 RUNDIR=/var/run/citadel
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin
16 DESC="Citadel Groupware "
17 NAME=citserver
18 DAEMON=/usr/sbin/$NAME
19 PIDFILE=$RUNDIR/citadel.pid
20 DAEMON_ARGS=" -d -x3 -lmail -t/dev/null"
21 SCRIPTNAME=/etc/init.d/citadel
22 SENDCOMMAND=/usr/sbin/sendcommand
24 # Exit if the package is not installed
25 [ -x "$DAEMON" ] || exit 0
27 # Read configuration variable file if it is present
28 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
30 MODERN=
32 # Load the VERBOSE setting and other rcS variables
33 if test -f /lib/init/vars.sh ; then
34 . /lib/init/vars.sh
35 MODERN=1
37 # Define LSB log_* functions.
38 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
39 if test -f /lib/lsb/init-functions; then
40 . /lib/lsb/init-functions
41 MODERN=1
45 # Function that starts the daemon/service
47 do_start()
49 # for ubuntu: check our volatile dirs.
50 if test ! -d $RUNDIR; then
51 mkdir -p $RUNDIR
53 # Return
54 # 0 if daemon has been started
55 # 1 if daemon was already running
56 # 2 if daemon could not be started
57 if $DAEMON \
58 $DAEMON_ARGS ; then
59 return 0
60 else
61 return 2
66 # Function that stops the daemon/service
68 do_stop()
70 # Return
71 # 0 if daemon has been stopped
72 # 1 if daemon was already stopped
73 # 2 if daemon could not be stopped
74 # other if a failure occurred
75 if $SENDCOMMAND "DOWN" >/dev/null 2>&1 ; then
76 if test ! -f "$PIDFILE"; then
77 echo Unable to find Citserver. Not running?
78 return 1
80 PID=`cat $PIDFILE`
81 rm -f $PIDFILE
82 count=0;
83 while test -S /var/run/citadel/citadel.socket -o -d /proc/$PID; do
84 count=$(($count+1))
85 sleep 1
86 echo -n "."
87 if test "$count" = "10"; then
88 kill $PID
90 if test "$count" = "20"; then
91 kill -9 $PID
92 rm -rf /var/run/citadel/*
94 done
95 return 0
96 else
97 rm -f $PIDFILE
98 return 2
103 # Function that sends a SIGHUP to the daemon/service
105 do_reload() {
106 # Return
107 # 0 if daemon could not be restarted
108 # 1 if daemon has been restarted
109 # other if a failure occurred
110 if $SENDCOMMAND "DOWN 1" 2>&1|grep '200 Restarting'>/dev/null ; then
111 return 1
113 return 0
116 case "$1" in
117 start)
118 if test -n "$MODERN"; then
119 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
120 else
121 echo "Starting $DESC" "$NAME"
124 do_start
125 if test -n "$MODERN"; then
126 case "$?" in
127 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
128 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
129 esac
132 stop)
133 if test -n "$MODERN"; then
134 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
135 else
136 echo "Stopping $DESC" "$NAME"
138 do_stop
139 if test -n "$MODERN"; then
140 case "$?" in
141 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
142 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
143 esac
146 restart|force-reload)
147 if test -n "$MODERN"; then
148 log_daemon_msg "Restarting $DESC" "$NAME"
149 else
150 echo "Restarting $DESC" "$NAME"
153 do_reload
155 if test -n "$MODERN"; then
156 case "$?" in
158 log_end_msg 0
161 # Failed to stop
162 log_end_msg 1
164 esac
168 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
169 exit 3
171 esac
173 exit 0