#!/bin/sh
#
# ulogd		Starts ulogd.
#
# chkconfig:	2345 91 91
# description:	ulogd is the userland packect logger for iptables ULOG target.

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

[ -f /usr/sbin/ulogd ] || exit 0

# Get service config
if [ -f /etc/sysconfig/ulogd ]; then
	. /etc/sysconfig/ulogd
fi

RETVAL=0
# See how we were called.
CONFIGS=/etc/ulogd.conf
if [ "${MULTIPLE}" == "YES" ]; then
	CONFIGS="$CONFIGS /etc/ulogd/*.conf"
fi

case "$1" in
  start)
	# Check if the service is already running?
	for i in $CONFIGS; do
		bname=$(basename $i .conf)
		if [ ! -f /var/lock/subsys/ulogd-$bname ]; then
			msg_starting ulogd-$bname
			daemon ulogd -d -c $i
			RETVAL=$?
			[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ulogd-$bname
		else
			msg_already_running ulogd-$bname
		fi
		touch /var/lock/subsys/ulogd
	done
	;;
  stop)
	if [ -f /var/lock/subsys/ulogd ]; then
		msg_stopping ulogd
		killproc ulogd
		rm -f /var/lock/subsys/ulogd* >/dev/null 2>&1
	else
		msg_not_running ulogd
	fi
	;;
  status)
	status ulogd
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
