#!/bin/sh
#
# /etc/init.d/conntrackd
#
#
### BEGIN INIT INFO
# Provides:		conntrackd
# Required-Start:	$network $time
# Required-Stop:	$network $time
# Default-Start:	S 2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Synchronized netfilter conntection tracking tables
# Description:		Keep the netfilter connection tracking tables in sync
#			with other machines or gather statistics about them.
### END INIT INFO
#
# Maximilian Wilhelm <max@rfc2324.org>
#  -- Mon, 06 Nov 2006 18:39:07 +0100
#

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME="conntrackd"
DAEMON=`command -v conntrackd`
CONFIG_FILE="/etc/conntrackd/conntrackd.conf"
DEFAULT_FILE="/etc/default/conntrackd"

# Gracefully exit if there is no daemon (debian way of life)
if [ ! -x "${DAEMON}" ]; then
	exit 0
fi

# Load the default file if provided
if [ -f "${DEFAULT_FILE}" ]; then
	. "${DEFAULT_FILE}"
fi


case "$1" in
  start)
	echo -n "Starting ${NAME}: "

	if [ "${START_CONNTRACKD}" != "true" ]; then
		echo "conntrackd not activated in ${DEFAULT_FILE}" >&2
		exit 0
	fi

	# Check for config file
	if [ ! -f "${CONFIG_FILE}" ]; then
		echo "Error: There is no config file for ${NAME}" >&2
		exit 1;
	fi

	start-stop-daemon --start --quiet --make-pidfile --pidfile "/var/run/${NAME}.pid" --background --exec "${DAEMON}"  && echo "done." || echo "FAILED!"
	;;

  stop)
        echo -n "Stopping ${NAME}: "
	start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/${NAME}.pid" && echo "done." || echo "FAILED!"
	;;

  restart|force-reload)
	$0 start
	$0 stop
	;;

  *)
	echo "Usage: /etc/init.d/ssh {start|stop|restart|force-reload}"
	exit 1
	;;

esac

exit 0

# vim:ft=sh

