1

I am currently doing a project that involves reading info from a citizen card. The project is working if I open an ssh console and start it by doing sudo java -Dsun.security.smartcardio.library=/usr/lib/arm-linux-gnueabihf/libpcsclite.so.1 -jar CCeltejo.jar.

Now I am trying to start the problem on boot, but it is saying that i don't have any smartcard readers connected. In order to get here I created a script with start and stop methods..

Here is the script:

#! /bin/sh
# /etc/init.d/CCidadao
## BEGIN INIT INFO
# Provides: CCidadao
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from http://www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting Service Citizen Card Reader"
# run application you want to start
sudo java -Dsun.security.smartcardio.library=/usr/lib/arm-linux-gnueabihf/libpcsclite.so.1 -jar /home/pi/NetBeansProjects/CeltejoCC/dist/CeltejoCC.jar
;;
stop)
echo "Stopping Service Citizen Card Reader"
# kill application you want to stop
pid=$(sudo ps aux | grep [C]eltejoCC.jar | awk '{print $2}')
echo $pid
sudo kill -9 $pid
echo "Service Stoped"
;;
*)
echo "Usage: /etc/init.d/CCidadao {start|stop}"
exit 1
;;
esac

exit 0

and then by doing sudo update-rc.d /etc/init.d/CCidadao defaults the program is initiated on boot.

The script is working because when I do /etc/init.d/CCidadao.sh start | stop the program starts and i can obtain from the card.

I also create a log file in order to see what is happening. When starting the Raspberry the program does indeed initiate, but does not discover any smart card reader.

When I do ls on /etc/rc2.d I am seeing s02pcscd and s06 CCidadaosh (my script), the pscs is the library that I use to communicate with the smartcard reader and obtained raw data from the cards.

I think that i am trying to launch the script way to early. What could I be doing wrong?

1

My best guess is that Smartcard Reader is not initiated and known by the system when your service is started.

To wait for the device management to be completed, you can simply add udev or udev-finish service (don't know the exact one) to your service's Required-Start line as follow.

# Required-Start: $remote_fs $syslog udev
0

I'm not an expert but I think the problem might be the user that runs the script at boot vs your user when you run it manually.

You can elevate, whatever user runs the script at boot probably can't.

If this is correct, try setting the owner of the script to "Pi" then set the suid bit.

You might be able to set the owner to root directly somehow but I'm not totally sure that would work these days.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.