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.
13
# Author: Fabian Fagerholm <fabbe@debian.org>
15
# Based on previous work by Dima Barsky.
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"
23
DAEMON=/usr/sbin/$NAME
25
SCRIPTNAME=/etc/init.d/$NAME
26
FALLBACK_RUN_DIR=/var/run/$NAME
29
# Exit if the daemon is not installed
30
test -x "$DAEMON" || exit 0
32
# Read configuration variable file if it is present
33
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
35
# Load the VERBOSE setting and other rcS variables
36
[ -f /etc/default/rcS ] && . /etc/default/rcS
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
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
48
PIDFILE=$RUN_DIR/saslauthd.pid
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"
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," \
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"
69
# Construct argument string
70
DAEMON_ARGS="$DAEMON_ARGS -a $MECHANISMS $MECH_OPTIONS $OPTIONS -n $THREADS"
73
# Function that creates a directory with the specified
74
# ownership and permissions
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"
87
# Function that starts the daemon/service
92
# 0 if daemon has been started
93
# 1 if daemon was already running
94
# 2 if daemon could not be started
96
if dpkg-statoverride --list $RUN_DIR > /dev/null; then
97
dir=`dpkg-statoverride --list $RUN_DIR`
99
test -z "$dir" || createdir $dir
101
start-stop-daemon --start --quiet --pidfile $PIDFILE --name $NAME \
102
--exec $DAEMON --test > /dev/null \
104
start-stop-daemon --start --quiet --pidfile $PIDFILE --name $NAME \
105
--exec $DAEMON -- $DAEMON_ARGS \
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.
113
# Function that stops the daemon/service
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
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 \
134
[ "$?" = 2 ] && return 2
135
# Many daemons don't delete their pidfiles when they exit.
141
# Function that sends a SIGHUP to the daemon/service
145
# If the daemon can reload its configuration without
146
# restarting (for example, when it is sent a SIGHUP),
147
# then implement that here.
149
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
156
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
159
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
160
1) [ "$VERBOSE" != no ] && log_progress_msg "(already running)" && \
162
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
166
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
169
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
170
1) [ "$VERBOSE" != no ] && log_progress_msg "(not running)" && \
172
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
175
#reload|force-reload)
177
# If do_reload() is not implemented then leave this commented out
178
# and leave 'force-reload' as an alias for 'restart'.
180
#log_daemon_msg "Reloading $DESC" "$NAME"
184
restart|force-reload)
186
# If the "reload" option is implemented then remove the
187
# 'force-reload' alias
189
log_daemon_msg "Restarting $DESC" "$NAME"
196
1) log_end_msg 1 ;; # Old process is still running
197
*) log_end_msg 1 ;; # Failed to start
207
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2