- from PLD
[packages/pcsc-lite.git] / pcsc-lite-pcscd.init
1 #!/bin/sh
2 #
3 # pcscd         PC/SC Smartcard daemon
4 #
5 # chkconfig:    2345 12 88
6 #
7 # description: The PC/SC smart card daemon is a resource manager for the \
8 #              PC/SC lite and Musclecard frameworks.  It coordinates \
9 #              communications with smart card readers, smart cards, and \
10 #              cryptographic tokens that are connected to the system.
11 #
12 # processname: pcscd
13 # config:      /etc/reader.conf.d
14 #
15 # Note!  pcscd should be started after pcmcia, and shut down before it
16 # for smooth experience with PCMCIA readers.
17 #
18 # $Id$
19
20 # Source function library
21 . /etc/rc.d/init.d/functions
22
23 upstart_controlled
24
25 umask 077
26
27 # Set defaults
28 LOGLEVEL=""
29 PCSCD_OPTIONS=""
30
31 # Get service config - may override defaults
32 [ -f /etc/sysconfig/pcscd ] && . /etc/sysconfig/pcscd
33
34 pidfile=/var/run/pcscd/pcscd.pid
35
36 start() {
37         if [ -f /var/lock/subsys/pcscd ]; then
38                 msg_already_running "PC/SC smart card daemon"
39                 return
40         fi
41
42         local logopt
43         case "$LOGLEVEL" in
44         debug|info|error|critical)
45                 logopt=--$LOGLEVEL
46         ;;
47         esac
48
49         msg_starting "PC/SC smart card daemon"
50         daemon /usr/sbin/pcscd $logopt $PCSCD_OPTIONS
51         RETVAL=$?
52         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pcscd
53 }
54
55 stop() {
56         if [ ! -f /var/lock/subsys/pcscd ]; then
57                 msg_not_running "PC/SC smart card daemon"
58                 return
59         fi
60
61         msg_stopping "PC/SC smart card daemon"
62         killproc --pidfile $pidfile pcscd
63         rm -f /var/lock/subsys/pcscd
64 }
65
66 condrestart() {
67         if [ ! -f /var/lock/subsys/pcscd ]; then
68                 msg_not_running "PC/SC smart card daemon"
69                 RETVAL=$1
70                 return
71         fi
72
73         stop
74         start
75 }
76
77 RETVAL=0
78 # See how we were called.
79 case "$1" in
80   start)
81         start
82         ;;
83   stop)
84         stop
85         ;;
86   restart)
87         stop
88         start
89         ;;
90   try-restart)
91         condrestart 0
92         ;;
93   force-reload)
94         # pcscd doesn't support reloading on HUP
95         condrestart 7
96         ;;
97   status)
98         status --pidfile $pidfile pcscd
99         RETVAL=$?
100         ;;
101   *)
102         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
103         exit 3
104 esac
105
106 exit $RETVAL