#!/bin/sh
#
# pathfinderd	X.509 Path Discovery and Validation Server
#
# chkconfig:	345 80 30
#
# description:	Pathfinder is designed to provide a mechanism for any program \
#		to perform RFC3280-compliant path validation of X.509 \
#		certificates, even when some of the intermediate certificates \
#		are not present on the local machine. It will automatically \
#		download any such certificates (and their CRLs) from the \
#		Internet as needed using the AIA and CRL distribution point \
#		extensions of the certificate it is processing.
#
# processname:	pathfinderd
# config:	/etc/pathfinderd.ini
#

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

# Get network config
. /etc/sysconfig/network

# 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 "pathfinderd"
		exit 1
	fi
else
	exit 0
fi

# Set defaults
RUNUSER="pathfinderd"
RUNFLAGS="-c ini:/etc/pathfinderd.ini -d"

# Get service config - may override defaults
. /etc/sysconfig/pathfinderd

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/pathfinderd ]; then
		msg_already_running "pathfinderd"
		return
	fi

	msg_starting "pathfinderd"
	daemon --user $RUNUSER /usr/sbin/pathfinderd $RUNFLAGS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pathfinderd
}

stop() {
	if [ ! -f /var/lock/subsys/pathfinderd ]; then
		msg_not_running "pathfinderd"
		return
	fi

	msg_stopping "pathfinderd"
	killproc pathfinderd
	rm -f /var/lock/subsys/pathfinderd
}

condrestart() {
	if [ ! -f /var/lock/subsys/pathfinderd ]; then
		msg_not_running "pathfinderd"
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status pathfinderd
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
