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.
Related
I want to make a Java Application that will start automatically when I start the computer and will run instead of the desktop, so the desktop-terminal etc will be unreachable for users. The users must use nothing but the application and when they close the application, the computer also must be turned off automatically. How can I do such a thing for a simple Java Application (jar)?
Shortly, for ubuntu you have to:
Remove desktop environment, just look around for some guides, it depends by which desktop you have (GNOME, XFCE, KDE, etc). https://askubuntu.com/a/147870
Add a script in /etc/rc.d and link it in rcS.d https://unix.stackexchange.com/a/83752.The script have to run your application, wait for end and shutdown,
an example could be:
#!/bin/bash
nohup java -jar MyApp.jar &
wait
/sbin/shutdown -r now
Try this in a virtual machine that you can reach in SSH or in some other ways, after you removed desktop environment, you cannot open a terminal.
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
How would one run the "bin/solr.cmd start" script so that it runs in the background in windows? Formerly, you could either run on tomcat and effectively run as a windows service. Alternatively, you could run the start.jar directly with "nohup" to prevent the hangup when the command prompt is closed.
With the release of Solr 5.0, it appears that Solr is now a standalone Java application that must be started with the start script (not a direct jar file).
Currently, if the command prompt that initiated the start command on Windows is closed, the application stops.
You can use Apache common deamon library or sc.exe (Windows Library) to "install" something as a service, which it sounds like you want.
I had the same problem upgrading from solr4
Solr 5 runs as a background service as default. Adding the -f parameter would run it in the foreground (which is needed if you run it as a windows service).
I'm using nssm (https://www.nssm.cc/download) to install Solr 5 as a windows service:
C:\nssm\nssm64.exe install "Solr 5.3.1" C:\search\solr-5.3.1\bin\solr.cmd "start -f -p 8983"
I am invoking a application on windows xp, 7 machines from remote linux using winexe. But I am not able to execute the application in foreground it executes in background. I tried psexec but no success. Can someone help me?
You have to run the application under the same user which is loged on on the windows-machine and use start # beginning of the cmd command.
How do I run a Java .jar file as a Windows service on a Windows 2008 server? I have a jar file called SomeJavaFile.jar located under the C:\SomeDirectory directory on a Windows Server 2008 box. I usually just run this jar manually in the command line with: java –cp SomeJavaFile.jar com.ctg.SomeJavaFile and I let it run 24/7.
The problem with our Windows Server is if it restarts I need to run it as a service so it will automatically start as a service upon startup, because our processing for Vistakon runs 24/7. I have Googled around and tried to use a service wrapper and the sc.exe command to create the service.
I put the wrapper service.exe in the C:\SomeDirectory\. I use the following command to create it: sc.exe SomeJavaService binPath= “C:\SomeDirectory\service.exe \”java –jar C:\SomeDirectory\SomeJavaFile.jar\”” type= own start= auto error= ignore. This creates the SomeJavaService service correctly but when I try to start it I get an error that says the service on Local Computer started then stopped.
Some services stop automatically if they are not in use by other services or programs. Do I need to alter my sc.exe command to have the exact previous working command line maybe, by adding in the com.ctg.SomeJavaFile? So should I change This jar should just run in the background and constantly poll/ping the C:/poll directory then if there is data present it processes the data and sends an export file to another directory.
I have used this same .jar file for years successfully and it hasn't changed, but I cannot get it to run as a Windows service. This is the site I use to get the service wrapper http://code.google.com/p/simple-service-wrapper/. Any help would be greatly appreciated!
"winsw" is the standalone version of the Windows Service installer shipping with the Glassfish Java EE reference implementation.
Works well, but is not a fully polished product - I have used it for exactly this purpose for a couple of years. Requires .NET in some recent version on the Windows machine.
https://github.com/kohsuke/winsw
I think that the best bet would be wrap your java app with Procrun of Apache Commons Daemon .
Procrun is a set of applications that allow Windows users to wrap
(mostly) Java applications (e.g. Tomcat) as a Windows service.
The service can be set to automatically start when the machine boots
and will continue to run with no user logged onto the machine.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat (that triggers the jar file)/.exe as a System service with all the required call back methods to SCM.
Note : 1. Wrapping the process with sc.exe / srvany.exe would not work as it does not have any call back process to the SCM (Service Control Manager). 2. And java service Wrapper is a third party API (many are LGPL licensed).
If you start your Java code from commandline by using java -j some.jar does it run until you terminate the program, or does it stop by itself?
There needs to be a NON-Deamon Thread, that is running all the time. A JVM will terminate, if there is no thread running, that is not flagged as daemon.
If you have a little budget, buy an installer tool. I use instll4j. With that tool, you can create service launcher and install them during instllation.
The following solution is working fine for me having OpenFire Connection Manager (which is a jar file) running as service on Windows Server.
Download and install the Non-Sucking Service Manager
I didn't use the batch made by OpenFire team, because it didn't work for me (dependencies not found error...) So, make a batch file with the following code :
#ECHO OFF
cd /D "E:\connection_manager\lib"
java -jar startup.jar
and save it as cm_startup.bat in the bin folder of connection manager.
After that you can create the service with NSSM.
So, open a cmd.exe and run the following command :
nssm install ConnManager "E:\connection_manager\lib\cm_startup.bat"
.
Doc & examples
More documentation and examples for the Non-Sucking Service Manager here : https://nssm.cc/usage Actually NSSM as a lot of options available.
Here is a more complexe example :
nssm install solr "%JavaExe%" -Dsolr.solr.home="\"%CD%\solr"\"
-Djetty.home="\"%CD%"\" -Djetty.logs="\"%CD%\logs"\" -cp
"\"%CD%\lib\*.jar"\";"\"%CD%\start.jar"\" -jar "\"%CD%\start.jar"\"