#! /bin/sh
#
# This shell script takes care of starting and stopping
# openct server
#
# chkconfig: 345 39 50
# description: Smartcard Terminal Tnterface
#
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/openct
DAEMON=/usr/sbin/openct-control

RETVAL=0

start() {
    action "Init OpenCT control" $DAEMON init
    touch "$LOCKFILE"
    RETVAL=$?
    return $RETVAL
}

stop() {
    action "Shutdown OpenCT control" $DAEMON shutdown
    rm -f "$LOCKFILE"
    RETVAL=$?
    return $RETVAL
}

restart() {
	stop
	sleep 1
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
	[ -e "$LOCKFILE" ]
	RETVAL=$?
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
		stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
  condreload)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
  restart|reload)
  	restart
	;;
  *)
	msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
