Sophie

Sophie

distrib > * > 2008.0 > x86_64 > by-pkgid > 05928626960bef94d2513847662b9e19 > files > 12

cyrus-sasl-2.1.22-23mdv2008.0.src.rpm

#!/bin/sh
#
# saslauthd     SASL AUTH Daemon
#
# chkconfig:    345 40 60
# description:  SASL AUTH Daemon
# processname:  saslauthd
# pidfile:      /var/lib/sasl2/saslauthd.pid

# $Id: saslauthd.init,v 1.1 2001/05/02 10:55:48 wiget Exp $

### BEGIN INIT INFO
# Provides: saslauthd
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 3 4 5
# Short-Description: Cyrus SASL auth daemon
# Description: The Cyrus SASL authentication daemon provides authentication
#              services to SASL enabled applications via several mechanisms
### END INIT INFO


# Source function library
. /etc/rc.d/init.d/functions

#Mux file directory
MUXDIR="/var/lib/sasl2"

PIDFILE="/var/lib/sasl2/saslauthd.pid"
LOCKFILE="/var/lock/subsys/saslauthd"

#Postfix spool directory (need to have the mux there as well)
PFDIR="/var/spool/postfix"


# Get service config
[ -f /etc/sysconfig/saslauthd ] && . /etc/sysconfig/saslauthd

# mech_options must be specified before the auth method

if [ "x$SASL_MECH_OPTIONS" != "x" ] ; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -O $SASL_MECH_OPTIONS"
fi

# compatibility with previous versions
if [ "x$SASL_RIMAP_HOSTNAME" != "x" ] ; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -O $SASL_RIMAP_HOSTNAME"
fi

if [ "x$SASL_AUTHMECH" != "x" ] ; then
	SASLAUTHD_OPTS="$SASLAUTHD_OPTS -a $SASL_AUTHMECH"
fi

RETVAL=0

# returns:
# 1: service running
# 0: service stopped
function is_running() {
	# Check if the service is already running?
        if [ ! -f "$PIDFILE" ]; then
		return 0
	else
		# pidfile exists, check if it's running
		pid=`head -n 1 "$PIDFILE"`
		if [ -d /proc/$pid ]; then
			# it's running, is it ours?
			if grep -q saslauthd /proc/$pid/cmdline; then
				return 1
			else
				return 0
			fi
		else
			return 0
		fi
	fi
	# not reached
	return 0
}


# See how we were called.
case "$1" in
  start)
  	is_running
	if [ "$?" -eq "0" ]; then
		rm -f "$LOCKFILE" "$PIDFILE"
		gprintf "Starting saslauthd"
		daemon saslauthd $SASLAUTHD_OPTS
		RETVAL=$?
		echo
		[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	else
		gprintf "saslauthd already running"
		echo_success
		echo
		exit 0
	fi
	# Check if Postfix is present and make a hardlink so
        # smtp auth can work
	if [ -e $PFDIR ]; then
		if [ ! -e ${PFDIR}${MUXDIR} ]; then
			gprintf "Creating %s%s\n" "${PFDIR}" "${MUXDIR}"
			mkdir -p ${PFDIR}${MUXDIR}
		fi
        	if [ ! -e ${PFDIR}${MUXDIR}/mux ];then
			if [ ! -e $MUXDIR/mux ];then
				  gprintf "Mux not ready... Sleeping 1 second\n"
				  sleep 1
			fi
			gprintf "Creating hardlink from %s/mux to %s%s/\n" "$MUXDIR" "${PFDIR}" "${MUXDIR}"
			ln -f $MUXDIR/mux ${PFDIR}${MUXDIR}/
		fi
	fi
	;;
  stop)
        # Stop daemons.
	is_running
	if [ "$?" -eq "1" ]; then
                gprintf "Stopping saslauthd"
                killproc saslauthd
		RETVAL=$?
		echo
		if [ "$RETVAL" -eq "0" ]; then
			rm -f /var/lock/subsys/saslauthd /var/run/saslauthd.pid >/dev/null 2>&1
        		if [ -e ${PFDIR}${MUXDIR}/mux ]; then
				gprintf "Deleting %s%s/mux\n" "${PFDIR}" "${MUXDIR}"
				rm -f ${PFDIR}${MUXDIR}/mux
			fi
		fi
        else
		gprintf "saslauthd not running"
		echo_success
		echo
	        exit 1
	fi
	;;
  status)
	status -p "$PIDFILE" saslauthd
	RETVAL=$?
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	gprintf "%s {start|stop|restart|status}\n" "$0"
	exit 1
	;;
esac

exit $RETVAL