#!/bin/sh
#
# portfwd	this program starts and stops the portfwd
#	        daemon.
#
# chkconfig:	345 82 18
#
# description:	portfwd is a program that forwards connections \
#		from the local machine to another machine.
#
# probe:	false
# config:	/etc/portfwd.cfg

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

# Source networking configuration.
. /etc/sysconfig/network

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

# Check that networking is up.
if [ "${NETWORKING}" = "no" ]; then
	echo "WARNING: Networking is down. portfwd can't be run."
	exit 1
fi

# Sanity check
[ -f /usr/sbin/portfwd ] || exit 0
[ -f /etc/portfwd.cfg ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/portfwd ]; then
		msg_starting portfwd
		daemon portfwd -c /etc/portfwd.cfg $PORTFWD_OPTIONS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/portfwd
	else
		msg_Already_Running "portfwd"
		exit 1
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/portfwd ]; then
		msg_stopping "portfwd"
		killproc portfwd
		rm -f /var/lock/subsys/portfwd >/dev/null 2>&1
	else
		msg_Not_Running "portfwd"
		exit 1
	fi
	;;
  status)
  	status portfwd
	exit $?
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  *)
	msg_Usage "$0 {start|stop|status|restart|reload}"
        exit 1
esac

exit $RETVAL
