Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here is my problem: I want to run a jar file at startup and have it run in a specified xwindow. 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 VNC server loads but at this point I am totally lost to understand what is going on. Thanks for any and all comments and help.

share|improve this question
    
I would look into invoking the application from your Xsession configuration, rather than via init. Since I haven't done that in years, and can't give you exact info, this isn't an answer. –  kdgregory Jun 2 '13 at 23:33
add comment

migrated from stackoverflow.com Jun 3 '13 at 5:23

This question came from our site for professional and enthusiast programmers.

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.