#!/bin/sh
#
# ocspd	OCSP Responder
#
# chkconfig: - 85 15
# description: OpenCA OCSP Responder
# processname: ocspd
# config: /etc/ocspd/ocspd.xml
# pidfile: /var/run/ocspd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/ocspd.pid
LOCKFILE=/var/lock/subsys/ocspd
OCSPDUSER=_ocspd
OCSPDGROUP=_ocspd
OCSPDBIN=/usr/sbin/ocspd
OCSPDCONF=/etc/ocspd/ocspd.xml

SourceIfExists /etc/sysconfig/ocspd

OCSPDARGS="-c $OCSPDCONF -d $OPTIONS"

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $OCSPDUSER -- $OCSPDBIN $OCSPDARGS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $OCSPDUSER -- $OCSPDBIN
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading tor
	stop_daemon --pidfile "$PIDFILE" --expect-user $OCSPDUSER -HUP -- $OCSPDBIN
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	start-verbose)
		OCSPDARGS="$OCSPDARGS -v"
		start
		;;
	start-debug)
		OCSPDARGS="$OCSPDARGS -v -debug"
		start
		;;
	start-wrongsig)
		OCSPDARGS="$OCSPDARGS -v -debug -testmode"
		start
		;;
	stop)
		stop
		;;
	reload-crl)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload-crl
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user $OCSPDUSER -- $OCSPDBIN
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|start-verbose|start-debug|start-wrongsig|stop|reload-crl|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
