#!/bin/bash
#
# pkcsslotd        Starts pkcsslotd
#
# Authors:	Kent E. Yoder <yoder1@us.ibm.com>
#		Serge E. Hallyn <serue@us.ibm.com>
#               Daniel H. Jones <danjones@us.ibm.com>
#
# chkconfig: - 50 50
# description: pkcsslotd is a daemon which manages cryptographic hardware \
# tokens for the openCryptoki package.

. /etc/init.d/functions

PIDFILE=/var/run/pkcsslotd.pid
LOCKFILE=/var/lock/subsys/pkcsslotd
SLOTDBIN=@sbindir@/pkcsslotd
CONFSTART=@sbindir@/pkcs11_startup


start() {
	[ -x $SLOTDBIN ] || exit 5
	[ -x $CONFSTART ] || exit 5

 	echo -n $"Starting pkcsslotd: "

        # Generate the configuration information
        $CONFSTART

        daemon $SLOTDBIN

	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch $LOCKFILE
	return $RETVAL
}	

stop() {
	echo -n $"Shutting down pkcsslotd:"
	killproc pkcsslotd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
	return $RETVAL
}

restart() {
	stop
	start
}

RETVAL=0
umask 077

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
  	status pkcsslotd $SLOTDBIN
	;;
  restart|reload|force-reload)
  	restart
	;;
  condrestart)
  	[ -f $LOCKFILE ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
	exit 2
esac

exit $?
