~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/citadel

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          citadel
 
4
# Required-Start:    $remote_fs $syslog
 
5
# Required-Stop:     $remote_fs $syslog
 
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
 
11
# uncomment this to create coredumps as described in
 
12
# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files
 
13
# ulimit -c unlimited
 
14
 
 
15
# Author: Wilfried Goesgens <citadel@outgesourced.org>
 
16
 
 
17
RUNDIR=/var/run/citadel
 
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
19
DESC="Citadel Groupware "
 
20
NAME=citserver
 
21
DAEMON=/usr/sbin/$NAME
 
22
PIDFILE=$RUNDIR/citadel.pid
 
23
DAEMON_ARGS=" -d -x3 -lmail -t/dev/null"
 
24
SCRIPTNAME=/etc/init.d/citadel
 
25
SENDCOMMAND=/usr/sbin/sendcommand
 
26
 
 
27
# Exit if the package is not installed
 
28
[ -x "$DAEMON" ] || exit 0
 
29
 
 
30
# Read configuration variable file if it is present
 
31
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
32
 
 
33
MODERN=
 
34
 
 
35
# Load the VERBOSE setting and other rcS variables
 
36
if test -f /lib/init/vars.sh ; then
 
37
    . /lib/init/vars.sh
 
38
    MODERN=1
 
39
fi
 
40
# Define LSB log_* functions.
 
41
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
42
if test -f /lib/lsb/init-functions; then
 
43
    . /lib/lsb/init-functions
 
44
    MODERN=1
 
45
fi
 
46
 
 
47
#
 
48
# Function that starts the daemon/service
 
49
#
 
50
do_start()
 
51
{
 
52
        # check our volatile dirs.
 
53
        if test ! -d $RUNDIR; then
 
54
            mkdir -p $RUNDIR
 
55
            chmod go+rx $RUNDIR
 
56
        fi
 
57
        # Return
 
58
        #   0 if daemon has been started
 
59
        #   1 if daemon was already running
 
60
        #   2 if daemon could not be started
 
61
        if $DAEMON \
 
62
                $DAEMON_ARGS ; then
 
63
            return 0
 
64
        else
 
65
            return 2
 
66
        fi
 
67
}
 
68
 
 
69
#
 
70
# Function that stops the daemon/service
 
71
#
 
72
do_stop()
 
73
{
 
74
        if test -S $RUNDIR/citadel.socket; then 
 
75
            sendcommand "DOWN" || :
 
76
        fi
 
77
 
 
78
        PID=`cat $PIDFILE 2>/dev/null || :`
 
79
        if [ ! -z $PID ]; then
 
80
            rm -f $PIDFILE
 
81
            count=0;
 
82
            while test -S /var/run/citadel/citadel.socket -o -d /proc/$PID; do 
 
83
                count=$(($count+1))
 
84
                sleep 1
 
85
                echo -n "."
 
86
                if test "$count" = "10"; then
 
87
                    kill $PID >/dev/null 2>&1
 
88
                fi
 
89
                if test "$count" = "20"; then
 
90
                    kill -9 $PID >/dev/null 2>&1
 
91
                    rm -rf /var/run/citadel/*
 
92
                fi
 
93
            done
 
94
        fi
 
95
 
 
96
        return 0
 
97
}
 
98
 
 
99
#
 
100
# Function that sends a SIGHUP to the daemon/service
 
101
#
 
102
do_reload() {
 
103
        # Return
 
104
        #   0 if daemon could not be restarted
 
105
        #   1 if daemon has been restarted
 
106
        #   other if a failure occurred
 
107
        if $SENDCOMMAND "DOWN 1" 2>&1|grep '200 Restarting'>/dev/null ; then
 
108
            return 1
 
109
        fi
 
110
        return 0
 
111
}
 
112
 
 
113
case "$1" in
 
114
  start)
 
115
        if test -n "$MODERN"; then
 
116
            [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
117
        else
 
118
            echo "Starting $DESC" "$NAME"
 
119
        fi
 
120
 
 
121
        do_start
 
122
        if test -n "$MODERN"; then
 
123
            case "$?" in
 
124
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
125
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
126
            esac
 
127
        fi
 
128
        ;;
 
129
  stop)
 
130
        if test -n "$MODERN"; then
 
131
            [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
132
        else
 
133
            echo "Stopping $DESC" "$NAME"
 
134
        fi
 
135
        do_stop
 
136
        if test -n "$MODERN"; then
 
137
                [ "$VERBOSE" != no ] && log_end_msg 0
 
138
        fi
 
139
        ;;
 
140
  restart)
 
141
        $0 stop
 
142
        $0 start
 
143
        ;;
 
144
  force-reload)
 
145
        if test -n "$MODERN"; then
 
146
            log_daemon_msg "Restarting $DESC" "$NAME"
 
147
        else
 
148
            echo "Restarting $DESC" "$NAME"
 
149
        fi
 
150
 
 
151
        do_reload
 
152
 
 
153
        if test -n "$MODERN"; then
 
154
            case "$?" in
 
155
                0)
 
156
                    log_end_msg 0
 
157
                    ;;
 
158
                1)
 
159
                # Failed to stop
 
160
                    log_end_msg 1
 
161
                    ;;
 
162
            esac
 
163
        fi
 
164
        ;;
 
165
 
 
166
  status)
 
167
        status_of_proc "$DAEMON" $NAME
 
168
        ;;
 
169
 
 
170
  *)
 
171
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 
172
        exit 3
 
173
        ;;
 
174
esac
 
175
 
 
176
exit 0