#!/bin/sh
# nullmailer - Simple relay-only mail transport agent
#
# chkconfig:	345 80 30
# description:	nullmailer - Simple relay-only mail transport agent

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

# Get network config
. /etc/sysconfig/network

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

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down "nullmailer"
		exit 1
	fi
else
	exit 0
fi

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/nullmailer ]; then
		msg_starting "nullmailer"
		daemon --fork --user nullmail "/sbin/initlog -f mail -c nullmailer-send >/dev/null 2>/dev/null"
		touch /var/lock/subsys/nullmailer
	else
		msg_already_running "nullmailer"
	fi
	;;
  stop)
	# Check if the service is already running?
	if [ -f /var/lock/subsys/nullmailer ]; then
		msg_stopping "nullmailer"
		busy
		killproc nullmailer-send
		rm -f /var/lock/subsys/nullmailer
	else
		msg_not_running "nullmailer"
	fi
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  status)
	status nullmailer nullmailer-send
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
