#!/bin/sh
#
# Startup script for the PRQPD responder
#
# chkconfig: 345 85 15
# description: OpenCA PRQP Responder
# processname: openca-prqpd

prefix="/usr";
sbin="${prefix}/sbin";
etc="${prefix}/etc/prqpd"
var="${prefix}/var"

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

prqpd="${sbin}/prqpd";
conf="${etc}/prqpd.xml";

# Take a look in your apache config and set it as it is set there.
pidfile="${var}/prqpd.pid";

# See how we were called.
case "$1" in
  start)
	echo -n "Starting PRQP Responder: "
	${prqpd} -c "${conf}" -d
	echo "Done."
	;;
  start-verbose)
	echo -n "Starting PRQP Responder: "
	${prqpd} -c "${conf}" -d -v
	echo "Done."
	;;
  start-debug)
	echo -n "Starting PRQP Responder: "
	${prqpd} -c "${conf}" -d -v -debug
	echo "Done."
	;;
  stop)
	echo -n "Shutting down PRQP Responder: "
	if [ -f "$pidfile" ] ; then
		pid=`cat $pidfile`;
		if [ "x$pid" = "x" ] ; then
		 	pkill prqpd
		else
			kill ${pid}
		fi
		rm -f "$pidfile"
	else
		echo "Missing pidfile (already stopped?)"
	fi
	echo "Done."
	;;
  status)
	echo -n "PRQP Responder is "
	if ! [ -f "$pidfile" ] ; then
		echo "stopped."
	else
		pid=`cat $pidfile`;
		ret=`ps -p ${pid}`;
		if test $? -eq 0 ; then
			echo "running ( $pid ) ... "
		else
			echo "stopped."
		fi
	fi
	;;
  reload-crl)
	echo -n "Sending Reload CRL Signal to PRQP ... "
	if ! [ -f "$pidfile" ] ; then
		echo "stopped."
	else
		pid=`cat $pidfile`;
		if test `kill -HUP ${pid}` ; then
			echo "error."
		else
			echo "Ok."
		fi
	fi
	;;
  restart)
	$0 stop
	sleep 2
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|status|reload-crl|restart}"
	exit 1
esac

exit 0
