~ubuntu-branches/ubuntu/gutsy/cyrus-sasl2/gutsy-201105300151

« back to all changes in this revision

Viewing changes to debian/sasl2-bin.saslauthd.init

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2006-11-27 12:59:40 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061127125940-na3q3g3tkydvyvgl
Tags: 2.1.22.dfsg1-4ubuntu1
* Merge from debian unstable, remaining changes:
  - remove stop links from rc0 and rc6
  - build against db4.3 instead of 4.2
  - build against heimdal-dev instead of libkrb5-dev
  - depend on, don't recommend, modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          saslauthd
 
4
# Required-Start:    $local_fs $remote_fs
 
5
# Required-Stop:     $local_fs $remote_fs
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      S 0 1 6
 
8
# Short-Description: saslauthd startup script
 
9
# Description:       This script starts the saslauthd daemon. It is
 
10
#                    configured using the file /etc/default/saslauthd.
 
11
### END INIT INFO
 
12
 
 
13
# Author: Fabian Fagerholm <fabbe@debian.org>
 
14
#
 
15
# Based on previous work by Dima Barsky.
 
16
 
 
17
# Do NOT "set -e"
 
18
 
 
19
# PATH should only include /usr/* if it runs after the mountnfs.sh script
 
20
PATH=/usr/sbin:/usr/bin:/sbin:/bin
 
21
DESC="SASL Authentication Daemon"
 
22
NAME=saslauthd
 
23
DAEMON=/usr/sbin/$NAME
 
24
DAEMON_ARGS=""
 
25
SCRIPTNAME=/etc/init.d/$NAME
 
26
FALLBACK_RUN_DIR=/var/run/$NAME
 
27
EXIT_ERROR_CODE=1
 
28
 
 
29
# Exit if the daemon is not installed
 
30
test -x "$DAEMON" || exit 0
 
31
 
 
32
# Read configuration variable file if it is present
 
33
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
34
 
 
35
# Load the VERBOSE setting and other rcS variables
 
36
[ -f /etc/default/rcS ] && . /etc/default/rcS
 
37
 
 
38
# Define LSB log_* functions.
 
39
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
40
. /lib/lsb/init-functions
 
41
 
 
42
# Determine run directory and pid file location by looking for an -m option.
 
43
RUN_DIR=`echo "$OPTIONS" | xargs -n 1 echo | sed -n '/^-m$/{n;p}'`
 
44
if [ -z "$RUN_DIR" ]; then
 
45
        # No run directory defined in defaults file, use fallback
 
46
        RUN_DIR=$FALLBACK_RUN_DIR
 
47
fi
 
48
PIDFILE=$RUN_DIR/saslauthd.pid
 
49
 
 
50
# If the daemon is not enabled, give the user a warning and then exit,
 
51
# unless we are stopping the daemon
 
52
if [ "$START" != "yes" -a "$1" != "stop" ]; then
 
53
        log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
 
54
        exit 0
 
55
fi
 
56
 
 
57
# If no mechanisms are defined, log this and exit
 
58
if [ -z "$MECHANISMS" ]; then
 
59
        log_failure_msg "No mechanisms defined in /etc/default/$NAME," \
 
60
                        "not starting $NAME"
 
61
        exit $EXIT_ERROR_CODE
 
62
fi
 
63
 
 
64
# If there are mechanism options defined, prepare them for use with the -O flag
 
65
if [ -n "$MECH_OPTIONS" ]; then
 
66
        MECH_OPTIONS="-O $MECH_OPTIONS"
 
67
fi
 
68
 
 
69
# Construct argument string
 
70
DAEMON_ARGS="$DAEMON_ARGS -a $MECHANISMS $MECH_OPTIONS $OPTIONS -n $THREADS"
 
71
 
 
72
#
 
73
# Function that creates a directory with the specified
 
74
# ownership and permissions
 
75
#
 
76
createdir()
 
77
{
 
78
# $1 = user
 
79
# $2 = group
 
80
# $3 = permissions (octal)
 
81
# $4 = path to directory
 
82
        # In the future, use -P/-Z to have SE Linux enhancement.
 
83
        install -d --group="$2" --mode="$3" --owner="$1" "$4"
 
84
}
 
85
 
 
86
#
 
87
# Function that starts the daemon/service
 
88
#
 
89
do_start()
 
90
{
 
91
        # Return
 
92
        #   0 if daemon has been started
 
93
        #   1 if daemon was already running
 
94
        #   2 if daemon could not be started
 
95
 
 
96
        if dpkg-statoverride --list $RUN_DIR > /dev/null; then
 
97
                dir=`dpkg-statoverride --list $RUN_DIR`
 
98
        fi
 
99
        test -z "$dir" || createdir $dir
 
100
 
 
101
        start-stop-daemon --start --quiet --pidfile $PIDFILE --name $NAME \
 
102
                --exec $DAEMON --test > /dev/null \
 
103
                || return 1
 
104
        start-stop-daemon --start --quiet --pidfile $PIDFILE --name $NAME \
 
105
                --exec $DAEMON -- $DAEMON_ARGS \
 
106
                || return 2
 
107
        # Add code here, if necessary, that waits for the process to be ready
 
108
        # to handle requests from services started subsequently which depend
 
109
        # on this one.  As a last resort, sleep for some time.
 
110
}
 
111
 
 
112
#
 
113
# Function that stops the daemon/service
 
114
#
 
115
do_stop()
 
116
{
 
117
        # Return
 
118
        #   0 if daemon has been stopped
 
119
        #   1 if daemon was already stopped
 
120
        #   2 if daemon could not be stopped
 
121
        #   other if a failure occurred
 
122
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
 
123
                --pidfile $PIDFILE --name $NAME
 
124
        RETVAL="$?"
 
125
        [ "$RETVAL" = 2 ] && return 2
 
126
        # Wait for children to finish too if this is a daemon that forks
 
127
        # and if the daemon is only ever run from this initscript.
 
128
        # If the above conditions are not satisfied then add some other code
 
129
        # that waits for the process to drop all resources that could be
 
130
        # needed by services started subsequently.  A last resort is to
 
131
        # sleep for some time.
 
132
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
 
133
                --exec $DAEMON
 
134
        [ "$?" = 2 ] && return 2
 
135
        # Many daemons don't delete their pidfiles when they exit.
 
136
        rm -f $PIDFILE
 
137
        return "$RETVAL"
 
138
}
 
139
 
 
140
#
 
141
# Function that sends a SIGHUP to the daemon/service
 
142
#
 
143
do_reload() {
 
144
        #
 
145
        # If the daemon can reload its configuration without
 
146
        # restarting (for example, when it is sent a SIGHUP),
 
147
        # then implement that here.
 
148
        #
 
149
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
 
150
                --name $NAME
 
151
        return 0
 
152
}
 
153
 
 
154
case "$1" in
 
155
  start)
 
156
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
157
        do_start
 
158
        case "$?" in
 
159
                0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
160
                1) [ "$VERBOSE" != no ] && log_progress_msg "(already running)" && \
 
161
                                           log_end_msg 0 ;;
 
162
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
163
        esac
 
164
        ;;
 
165
  stop)
 
166
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
167
        do_stop
 
168
        case "$?" in
 
169
                0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
170
                1) [ "$VERBOSE" != no ] && log_progress_msg "(not running)" && \
 
171
                                           log_end_msg 0 ;;
 
172
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
173
        esac
 
174
        ;;
 
175
  #reload|force-reload)
 
176
        #
 
177
        # If do_reload() is not implemented then leave this commented out
 
178
        # and leave 'force-reload' as an alias for 'restart'.
 
179
        #
 
180
        #log_daemon_msg "Reloading $DESC" "$NAME"
 
181
        #do_reload
 
182
        #log_end_msg $?
 
183
        #;;
 
184
  restart|force-reload)
 
185
        #
 
186
        # If the "reload" option is implemented then remove the
 
187
        # 'force-reload' alias
 
188
        #
 
189
        log_daemon_msg "Restarting $DESC" "$NAME"
 
190
        do_stop
 
191
        case "$?" in
 
192
          0|1)
 
193
                do_start
 
194
                case "$?" in
 
195
                        0) log_end_msg 0 ;;
 
196
                        1) log_end_msg 1 ;; # Old process is still running
 
197
                        *) log_end_msg 1 ;; # Failed to start
 
198
                esac
 
199
                ;;
 
200
          *)
 
201
                # Failed to stop
 
202
                log_end_msg 1
 
203
                ;;
 
204
        esac
 
205
        ;;
 
206
  *)
 
207
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 
208
        exit 3
 
209
        ;;
 
210
esac
 
211
 
 
212
: