#!/bin/sh
#
# spfd		spfd server
#
# chkconfig:	345 75 25
# description:	spfd is an SPF record checking daemon
# processname:	spfd


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

# Get network config
. /etc/sysconfig/network

# set defaults
SPFD_USER="nobody"
SPFD_GROUP="nobody"
SPFD_SOCKET="/var/run/spfd.socket"
OPTIONS="-pathuser=\"$SPFD_USER\" -pathgroup=\"$SPFD_GROUP\" -path=\"$SPFD_SOCKET\" -pathmode=666"

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

# 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 spfd
		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/spfd ]; then
		msg_starting spf
		daemon spfd $OPTIONS &
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/spfd
	else
		msg_already_running spfd
	fi
	;;
  stop)
	# Stop daemons.
	if [ -f /var/lock/subsys/spfd ]; then
		msg_stopping spfd
		killproc spfd
		rm -f /var/lock/subsys/spfd > /dev/null 2>&1
	else
		msg_not_running spfd
	fi
	;;
  status)
	status spfd
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
