B4J Question Raspberry run at boot in foreground

Michael Sergio

Member
Licensed User
Longtime User
Hi. I`m newb with linux. I`m trying to run a jar Non ui application at startup.
I have this sh script named run.sh:
B4X:
#!/bin/bash
[[ $# -eq 0 ]] && { echo -e "Usage:\t\t $0 <Process_name>"; exit 1;  }
while :
do
ifnotrun(){
        local p=$1
        if ! ps -C "$1" -opid=
        then
                cmd=($@)
                echo ${cmd[@]:1}
        echo "Program not started...starting Now..."
        sudo java -jar /home/pi/Documents/Test/testX.jar
        sleep 20
        else
                echo "Process \"$p\" Already Running.."
        fi

}

ifnotrun $*
sleep 15
done
I also added this in crontab:
B4X:
@reboot  bash /home/pi/Documents/Test/run.sh java >/home/pi/Documents/Test/logs/`date +\%Y-\%m-\%d_\%H:\%M:\%S`-appl.log 2>&1
The program starts ok, but it starts in background and i tried searching for solutions on the internet, cant seem to get the jar running at startup in foreground.
I need it in foreground, cause my app is starting the "omxplayer" and playing a video file.
If i manually run it, it works just fine, but if its running at startup, just runs in the background and i have no video.
I also checked the logs, app is starting ok, also checked the pidof java, i have a java app started.
Thank you.
 

xulihang

Active Member
Licensed User
Longtime User
maybe you should set up a startup item in your x windows settings?
I have done such kind of things under mac os using the system's startup function
 
Upvote 0
Top