#!/bin/sh
#=================================================================
# Begin pcscd
#
# Description : Start pcsc daemon
# chkconfig:	2345 95 5
#
#=================================================================

### BEGIN INIT INFO
# Provides:            pcscd
# Should-Start:
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Starts pcsc daemon.
# Description:         Starts pcsc daemon.
### END INIT INFO

. /lib/lsb/init-functions

RETVAL=0
PROG="pcscd"
CMD="/usr/sbin/$PROG"
PID_FILE=/run/$PROG/$PROG.pid

#preparing pid file
mkdir -p /run/$PROG
chown root:root /run/$PROG

# Some functions to make the below more readable
case "$1" in
    start)
        log_info_msg "Starting $PROG daemon..."
        start_daemon $CMD 
        evaluate_retval
        ;;

    stop)
	log_info_msg "Stopping $PROG Server..."
	killproc -p $PID_FILE $CMD
	evaluate_retval
        ;;

    reload)
	log_info_msg "Reloading $PROG Server..."
	$CMD -H
	evaluate_retval
        ;;

    condrestart)
	pid=`cat $PID_FILE 2>/dev/null`
	if [ -n "${pid}"  -a -d /proc/$pid ]; then
  	  $0 restart
  	  fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    *)
        echo "Usage: $0 {start|stop|reload|condrestart|restart}"
        exit 1
        ;;
esac

