#!/bin/sh
#
# smtptrapd	SMTP service that always returns a 4xx soft error to the RCPT TO verb.
#
# chkconfig: - 90 10
# description:	The smtptrapd program is a multi-threaded daemon \
#               that provides a RFC 2821 compliant SMTP service that \
#               always returns a 4xx soft error to the RCPT TO verb.
# processname: smtptrapd
# config: /etc/sysconfig/smtptrapd
# pidfile: /var/run/smtptrapd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/smtptrapd.pid
LOCKFILE=/var/lock/subsys/smtptrapd
RETVAL=0

# Configuration
. /etc/sysconfig/smtptrapd
CMD_LINE="-f $PIDFILE"
[ "$CHROOT" ] && CMD_LINE="$CMD_LINE -c $CHROOT"
[ "$CHUSER" ] && CMD_LINE="$CMD_LINE -u $CHUSER"
[ "$CHUSER" ] || CHUSER=root
[ "$THREADS" ] && CMD_LINE="$CMD_LINE -t $THREADS"
[ "$THREADS" ] && CMD_LINE="$CMD_LINE -t $THREADS"
[ "$MAX_LEN" ] && CMD_LINE="$CMD_LINE -m $MAX_LEN"
[ "$SMTP_HOST" ] && CMD_LINE="$CMD_LINE -l $SMTP_HOST"
[ "$SMTP_PORT" ] && CMD_LINE="$CMD_LINE -p $SMTP_PORT"
[ "$HOST_NAME" ] && CMD_LINE="$CMD_LINE -b '$HOST_NAME'"


start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $CHUSER -- \
			/usr/sbin/smtptrapd $CMD_LINE
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $CHUSER -- /usr/sbin/smtptrapd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		restart
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user $CHUSER -- /usr/sbin/smtptrapd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
