1#!/bin/sh
2#
3# openct       This shell script takes care of starting and stopping OpenCT.
4#
5# chkconfig:   2345 24 89
6# description: OpenCT is a middleware framework for smart card terminals.
7#
8# processname: ifdhandler
9# config:      /etc/openct.conf
10
11### BEGIN INIT INFO
12# Provides: openct
13# Default-Start: 2 3 4 5
14# Default-Stop: 0 1 6
15# Should-Start: $syslog $network
16# Should-Stop: $syslog $network
17# Short-Description: Middleware framework for smart card terminals
18# Description: This starts/stops the OpenCT middleware framework support
19#              for smart card terminals.
20### END INIT INFO
21
22. /etc/init.d/functions
23
24exec="/usr/sbin/openct-control"
25prog=openct
26proc=ifdhandler
27
28OPENCT_OPTIONS=
29[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
30
31lockfile=/var/lock/subsys/$prog
32
33start() {
34    retval=0
35    if ! status $proc >/dev/null 2>&1 ; then
36        action $"Initializing OpenCT smart card terminals: " \
37            $exec $OPENCT_OPTIONS init
38        retval=$?
39        [ $retval -eq 0 ] && touch $lockfile
40    fi
41    return $retval
42}
43
44stop() {
45    if status $proc >/dev/null 2>&1 ; then
46        action $"Stopping OpenCT smart card terminals: " \
47            $exec $OPENCT_OPTIONS shutdown
48    fi
49    retval=$?
50    if [ $retval -eq 0 ] ; then
51        rm -f /var/run/openct/status
52        rm -f $lockfile
53    fi
54    return $retval
55}
56
57restart() {
58    stop
59    start
60}
61
62oct_status() {
63    status $proc
64    retval=$?
65    if [ -e /var/run/openct/status ] ; then
66        $exec $OPENCT_OPTIONS status
67        [ -e /var/run/openct/status ] && \
68            echo $"Waiting for reader attach/detach events..."
69    fi
70    return $retval
71}
72
73case "$1" in
74    start|stop|restart)
75        $1
76        ;;
77    reload|force-reload)
78        restart
79        ;;
80    status)
81        oct_status
82        ;;
83    try-restart|condrestart)
84  	[ ! -f $lockfile ] || restart
85	;;
86    *)
87        echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
88        exit 2
89esac
90