Booting Java Application On Startup - Raspberry Pi - Raspbian - Shell Script - java

I've been attempting to boot a java application via a shell script on a Raspberry Pi 2 startup for a while now with absolutely no success. I've been through countless threads and tutorials with no joy.
I'm running a java application via a shell script.
rc.local
I've tried putting a reference to the shell script in the etc/rc.local file.
I've had the application in the usr/local directory and i've also tried moving it to the home/pi folder. All permissions are set to full on every file.
su - pi -c "bash /home/pi/logon.sh &"
Has no effect on boot, the shell script runs fine when you run it from the terminal.
Chrontab
I've edited the chrontab file. I've tried multiple variants on the end of this file, again nothing worked on boot.
etc/init.d
I've also placed the shell script in this folder and ran the command: sudo update-rc.d /etc/init.d/logon.sh defaults. There are no complaints, it seems to work, shell script works when executed manually, however nothing starts up on boot.
I'm assuming that either Java isn't initiated at the point of boot or the shell script attempts to run before Raspbian boots into its interface since non of the above methods work. I don't mind losing the Raspbian interface if neccessary, in fact this would be preferable. I simply want a java application to start up when the Raspberry Pi boots. Any ideas?
Thanks

i've done it with this wrapper : https://stackoverflow.com/a/21283530/5066919
and you'll see that he use the "nohup" (no hang up) command, like this the app don't close when the user log out
Also becarefull if you use "scanner.hasNext()" command : https://stackoverflow.com/a/33456615/5066919

Related

Cannot run script/Java program on Raspberry Pi 3B boot

I'm simply trying to make a program run when the Raspberry boots up. The idea being it runs, so there is no need for a mouse/keyboard to manually start the program.
I've read forum after forum on how to run a script on boot on a Raspberry Pi. I feel like I've exhausted every method.
I have tried:
scheduling a cronjob
sudo crontab -e and then added the code
#reboot /file/path/myscript/
Putting my progam in the /etc/init.d/ folder and updating it in the boot sequence.
file moved to /etc/init.d/myscript/
make executable sudo chmod 755 /etc/init.d/myscript/
register script sudo update-rc.d defaults
Adding it to the .bashrc folder in the /pi directory
navigated to /home/pi/.bashrc/
added ./myscript/ to the file.
None of these have worked for me, whereas for everyone else on those forums, it seems to have solve their problem. Is there something I'm missing from any of these methods?

Can't execute java program on Raspberry Pi on startup

I use a Raspberry Pi 3 Model B with Raspbian Jessie.
I have a java program that I want to compile and run on start-up. I figured I need to launch it through /etc/rc.local. I have a command to compile the java-files and one command to run them.
sudo javac -cp
/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/bin/.jar
/home/pi/Desktop/MultiSensor_v2.0_Java/.java
sudo java
-Djava.library.path="/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/lib"
-cp "/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/bin/opencv-320.jar:/home/pi/Desktop/MultiSensor_v2.0_Java/"
Main &
When I run these commands from the terminal it works perfectly. I tried to put these commands in the /etc/rc.local file before exit 0. On reboot, the compilation works but the actual program never executes. How do I get my java program to run upon startup using the two commands above?
I had this problem, too. I solved it with the following workaround:
I created a shell-script that runs the java programm. Then I called the shell-script on startup.
I managed to solve it by doing a bash-script as #ILikeCOding said, but I had to change the location from were it was called.
I moved the bash-script to the root directory and edited the autostart script located in:
/home/pi/.config/lxsession/LXDE-pi/autostart
In that file, I added a line to launch my script. I think this works because the autostart-script launches when you log into your user and not on boot, therefore the program can launch properly. Not sure if that's the case, but it works so I'm happy.

Start java application in background automatically after boot on embedded linux

I am using an embedded linux ( Distro: TI SITARA SDK 6.0.0 ) on beaglebone black. I have a java application which runs multiple tcp servers. I need to start this application in background and automatically after every boot. If i login with ssh and run the below code manually (or in bash script) it does work.
nohup java -jar application.jar &>log.txt &
But if i add this in linux init script and reboot it doesn't.
If i delete last '&' in the line it does work but system resets after 2-3 minutes.
So how can i start my application after every bootup and not causing a reset ?
I solve this problem with starting my device's watchdog like application in my script. My application works in background but bash scripts stays open until my application stops.

Listen to serial port at STARTUP using java with arguments on Debian(Rasbian)

I've been stuck two weeks trying to figure out how to run this at startup.
I use the following chain of commands on the terminal:
1. source ~/.bashrc
2. source ~/.tinyos.sh
3. java net.tinyos.tools.Listen -comm serial#/dev/ttyUSB0:telosb | python demo.py`
The third command uses java to listen to the serial port and pipes it to a python script which cleans, converts and uploads to mysql localhost.
This works fine on ssh terminal. But ive tried using nohup+update-rc.d, upstart, systemd, crontab to make it run on startup and it just wont work! When I reboot and check logs / database, its as if the command never happened. I need this to run like a daemon and continue running until shutdown.
Thanks a lot.
How are you trying to execute the program ? Are there are permission issues accessing / executing the script ?
Which version of debian are you running - look at upstart scripts if you are running Jesse+
I'd put those three lines in a bash script and use upstart scripts to trigger them on start. Another option is to use supervisord to make sure that your scripts run and restart if for any reason the program crashes.

How to run Java application on startup of Ubuntu Linux

I have a requirement where I need to develop application that reads TCP/IP Socket. I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE. Now as per my requirement i have to start execution of this program as soon as Linux system Booted.
Actually I am very novice in Java and Linux Platform, so have few doubts..
Is my Socket Program with no GUI is fine to be run as per my requirement.
How can I write script to run jar on Linux Boot up, I got to know. init.d is meant for this.
Ideally you should create a service wrapper for your java application and then make this service run on startup example here.
Use
sudo update-rc.d mytestserv defaults to run your service wrapper on startup on Ubuntu
So two things you'll need to do:
First create a small shell script to start your java program from a terminal. As you have packaged as a jar have a look at this, specifically the JAR Files as Applications section.
This may be sufficient: (although you'll want to use the full path to Java)
#!/bin/bash
java -jar path_to_jar_file
You should be able to run your script and successfully start your program.
Once you've got it starting from a script you can use standard linux tools to start the script. Either putting it in /etc/rc.local, or as you're using Ubuntu, use update-rc.d to start it on boot. See here for a very simple example of using update-rc.d
Hope this helps,
Will

Categories