Sunday, June 2, 2013

Cannot auto- launch a jar file to display in a specified tightvnc session at startup. Multiple items tried with no positive results

Cannot auto- launch a jar file to display in a specified tightvnc session at startup. Multiple items tried with no positive results

by dxradio » Sun Jun 02, 2013 3:28 pm Hello, first let me say I am a noob so I apologize in advance for any visibly dumb mistakes. This is my problem: I want to run a jar file at startup and have it run in a specified xwindow (2) I can get everything to work with the exception of having it run at boot which is critical for unattended operation. This is what I have done: I have searched many archives about this subject. There have been numerous answers to similar questions but no approach that I use has worked for me.
I have installed tightVNC and have it running properly at startup. My code is as follows. I have a shell script that runs in /etc/init.d that basically starts the TightVNC server.
#!/bin/sh
### BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start:   $local_fs
# Required-Stop:    $local_fs
# Default-Start:    2 3 4 5
# Default-Stop:  0 1 6
# Short-Description:    Start/stop Vncserver
# Description:   Start vncserver at boot time
###END OF INIT INFO

export USER='pi'
eval cd "$USER"

case "$1"
start)
su $USER -c 'usr/bin/tightvncserver :2'
echo "Starting TightVNC server for $USER"
;
;
stop)
pkill Xtightvnc
echo "TightVNC Server stopped.
exit 1
;;
*)
esac
exit0
This works flawless and starts the VNC server at boot time. Now next I am doing the following to try to get my Java jar file to launch and display in the newly created xwindow . I have put two small shell scripts in a directory I created under /usr/local/bin/(myap-start.sh) and (myap-stop.sh) they look like this:
%!/bin/bash
# Start script for (myap)
# /usr/local/bin/(myap)

export DISPLAY=:2
export USER=:'pi'
java -jar /home/pi/myap/myap.jar &

and

#!/bin/bash
# Script used to kill the (myap) process
# Grabs and kills a process from the pidlist that has the word myap.jar.


pid=`ps aux | grep myap.jar | awk '{print $2}'`
kill -9 $pid
Lastly in the /etc/init.d folder I have this script.
#!/bin/bash
#myaprun
#
#description: This script hopefully will run the myap in background at startup of PI>
# This file goes in the /etc/init.d folder

# update-rc.d myaprun.sh defaults

case $1 in
start)
/bin/bash /usr/local/bin/myap-start.sh
;;
stop)
/bin/bash /usr/local/bin/myap-stop.sh
;;

esac
exit 0 
That's it. I have made all the files executable. Lastly the myaprun.sh has been registered as depency boot in init.d.
No matter what I do, I cannot get the application to launch at startup. After the pi boots I can run all the above scripts and they work just fine. I suspect that the above files are getting executed before the vncserver loads but at this point I am totally lost to understand what is going on. Thanks for any and all comments and help.