#!/bin/bash
#
#       /etc/rc.d/init.d/newpki
#
# Starts the NewPKI daemon
#
# chkconfig: 2345 98 18
# description: Starts the NewPKI daemon
# processname: newpki

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

prog="NewPKI"

pkistart(){

        gprintf "Starting %s: " "$prog"

        if test -e /var/lock/subsys/newpki; then
                echo_failure
                echo ""
                return 1
        fi

        newpki_server -config /etc/newpki/config.conf &
        sleep 3
        status newpki_server >/dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
                echo_success
                touch /var/lock/subsys/newpki
        else
                echo_failure
        fi
        echo ""
        return $ret
}

pkistop(){
	rm -f /var/lock/subsys/newpki 2> /dev/null
	killall newpki_server > /dev/null 2> /dev/null
    action "Stopping %s: " "$prog" /bin/true
	return 0
}
 
pkirestart(){
    pkistop
    sleep 10
    pkistart
}

# See how we were called.
case "$1" in
  start)
    pkistart
    ;;
  stop)
    pkistop
    ;;
  restart)
    pkirestart
    ;;
  status)
	status newpki_server
	exit $?
	;;
  *)
    gprintf "Usage: %s {start|stop|restart|status}\n" "$0"
    exit 1
esac

exit $?
