How to start a application without getting killed after log off? - java

I have a Java application which should run on a server machine in the background (the application can be started by a command without GUI). The problem is: When I log off from the server, the application gets killed. I'm looking for something similar like nohup under Linux. I found some solutions, but I'm unsure, what is the best for my situation (Windows Server 2003, Java Application run from BAT-Skript, restart after booting the machine)? What are the pros and cons of the solutions?
psexec: Do the process really need to run under the SYSTEM account?
Combination of instsrv and srvany: But srvany should should never be used in a production environment
I have started the application with the scheduled tasks with the option run as NT AUTHORITY\SYSTEM. But after log off, the application was still killed. Can I get this working?
The DOS Task Scheduler AT command

Write a windows service (on Java, C# - I don't think it does matter)
Start the app from your service
or
Run your app as a window service using 3d party utility

The only way in which you can get a process to run without a user being logged in is to have the process run as a windows service or at the very least called by a windows service.

Just to add to above answers.
Consider using http://wrapper.tanukisoftware.com.
It's rather mature and popular (in contrast to ServiceEx and RunAsService).

Yes, a Windows Service is definitely the way to go but there are a few things to watch out for when you run a Java application as a Windows Service. Most of them are covered in this tutorial showing how to setup a java application with our commercial run-anything-as-a-service application, AlwaysUp:
http://www.coretechnologies.com/products/AlwaysUp/Apps/RunJavaApplicationAsAService.html
Beware: You will almost surely need the "-Xrs" flag on Windows 2003 to prevent the closing-on-logoff behavior but things can get tricky if you are catching shutdown events. Let me know if that is an issue for your situation.

Related

Is there a Java equivalent to a windows service [duplicate]

This question already has answers here:
Run Java application at Windows startup
(8 answers)
Closed 6 years ago.
I know you can run a jar as a windows service by calling it from a batch file or something similar to that, and I know that when you use an application server such as WAS, or Glassfish you have JVMS's that are "running" per-se. But unless I am mistaken, those aren't necessarily "services". That is to say processes that are executing without input from any user. From my understanding you still need to call a JVM to get it to execute a process (and please feel free to correct me if I am wrong). But I have always been curious as to what is the Java/Linux equivalent of the Windows Service? Maybe it is JVM's running in an application server like Tomcat, or Glassfish.
A Windows Service is basically a background task that runs a process for you. In Windows, they are typically binary's (.exe's) that can hook into the Windows Service platform for startup and shutdown messages from the OS (and the services administration screen).
Anytime you execute Java, you need runtime component (JVM) to run it. Even Websphere and the other app servers are running in a JVM.
There isn't anything in Linux for you to hook into a "Service" per say, but you can emulate the functionality and run startup items in Linux at boot time.
It depends on the exact flavor of Linux being used, but the conceptual siblings to a Windows Service (i.e. a long-running daemon that the OS starts when the OS is started) are upstart, systemd, etc.

Experiencing high cpu consumption running Selenium-Server-standalone as a windows service

Thank you for viewing my post.
I'm running selenium-server-standalone as a windows service utilizing nssm(- the Non-Sucking Service Manager | http://nssm.cc/), utilizing the identical process as mentioned in this stackoverflow post #: https://stackoverflow.com/a/10656979/956863.
Quick Summary of post:
Download and extract nssm.exe
Installed NSSM and from the command line ran: nssm install Selenium-Server "C:\Program Files\Java\jre6\bin\java.exe" "-jar C:\Selenium\selenium-server-standalone-2.24.1.jar"
The machine where I'm running this process is running windows XP, service pack 3. This solution to run selenium server as a service works like a charm, and when selenium server is running, and crashes for some reason, selenium server successfully restarts without manual intervention.
But I"m coming into work, and am being informed by system administrators that high cpu alerts are being thrown. And again system logs are providing no information... So I'm wondering if selenium is actually the cause of this issue, and want to eliminate the possibility of running selenium as a service being blamed for this cpu spike.
Can anyone think of a solution, perhaps a way to stop the selenium service when cpu utilization reaches X amount? Or?
In the meantime, I'm going to set some sort of long term CPU utilization monitor and see if that can see something that the system monitor in xp may be missing. ( If anybody knows of a good way to achieve this, i'm open to suggestions as well )
I have selenium running as a service on windows 2008 server and noticed that its not able to clean up the headless browser instances. My tests are written in JavaScript with Soda so I have a start up and close out the browser instances but running as a service it doesn't close out those instances in the task manager.
I actually have two ways I'm running the service one way is where I'm using a bat file to run selenium the other way I have it running directly off a registry key.
I was able to fix the browser issue after I just added another step process to teamcity to run taskkill automatically on any browsers left open when the tests were complete. This fixed my CPU spiking issue.
Despite having vague reports of CPU spikes with Selenium as a service, I have yet to see one with my own eyes. Which version of Java are you using?
Our commercial run-anything-as-a-service product supports CPU tracking and can restart Selenium when it hogs the CPU. I suggest that you download the free 30-day trial and use it see if you can confirm or rule out Selenium as the problem in that time frame. Follow this guide to set up Selenium as a service.

Jboss/Tomcat monitor

I'm looking for a tool (in linux) that can montior a tomcat/jboss process and if the process fails, I can respawn either or both without having to manually ssh into the box, do any house keeping and then start them up again. I'm not too sure if there is a good tool out there that can monitor the health of jboss/tomcat and report on it's performance. I know jvisualvm gives you various tools, but I'm looking for a disaster recovery solution that is a bit higher level than jvisualvm.
Java Service Wrapper is an application that wraps your Java process and installs it in the system using service (Windows) or daemon (Linux). It pings the VM periodically and restarts it when it does not respond. Worked for us in production with several application, including Tomcat, JBoss, Mule, etc. Actually Mule ESB is even bundled with this application in the distribution.
Also you don't have to run the application manually when the system starts.
I'm currently working on a daemon to do this and more, since JOPR nor naggios didn't do what we needed, but those are good tools you could use. I'm not sure but JOPR (or whatever is called today) can restart your servers in case something goes wrong.
A custom made solution as we're working on shouldn't take you more than a week. The main problem, is that to start either JBoss or Tomcat you have to call the startup scripts. But the startup script will restart the service if the exit code is 10, something like this:
while $? -ne 10; do
start_jboss
done
So, this daemon which is made in Java uses JMX to connect to the JBoss server and tells JBoss to go down and exit with status code 10 using a method in a MBean. I'm at home, so I'm not sure the exact name of the MBean you have to call for this but I'll provide more info tomorrow.
I am using monit to control the launch of Tomcat/JBoss.

How to automatically run JBoss app on startup, using RedHat

Not too long ago, I installed a java web application on a Red Hat server running JBOSS.
After a recent reboot, I realized that the site did not start up automatically when the machine was booted.
Is there an easy way to ensure that this happens? There are shell scripts to start and stop the application, something like :
/opt/myApp/StartMyApp.sh
/opt/MyApp/StopMyApp.sh
I have been reading about Redhat Run Levels, (etc/rc.d), but it seems too complicated for what I need to do - just run the shell script after booting.
Making it a Windows service is quite easy, but I'm unfamiliar with how to do the equivalent with Redhat.
Thanks
It's been covered at
http://www.jboss.org/community/wiki/startjbossonbootwithlinux
edit: redhat page on that: http://www.redhat.com/docs/en-US/Red_Hat_Application_Stack/2.2/html/Release_Notes/sn-usingjbossas.html

Running a Java process in Windows even after the user is logged out

I have a batch file that starts a Java process in a Windows 2003 server. As per the security policy, the users of that machine are logged off forcefully, if the user is inactive for a certain period of time. The problem is that when the user is logged out, the process also dies.
I scheduled a new task (Control Panel -> Scheduled Tasks) and selected the option of 'When my computer starts' and gave the user account details there. But it doesn't seem to have any effect, the user is still logged out and the process dies. Is a reboot necessary to make this change effective? And after the reboot, will I achieve what I'm expecting (keeping the process alive)?
Alternatively, will running this process as a Windows Service solve the problem? If so, can you please let me know how I can make a Java program or a batch file to run as a Windows Service? I would prefer not to use any other third party tools or libraries.
Thanks
If you want it to run under Scheduled tasks you have to make sure you don't have "only run when user logged in" checked, which usually means you need to supply a password.
A windows service would be the normal way to do this: the Java service wrapper is 3rd party but loads of people use it.
If you really wanted to not use a 3rd party method you could use svrany.exe (http://support.microsoft.com/kb/137890) on WIndows NT or later, but it is not designed specifically for Java.
Wrapping the process with srvany.exe and launching as a service would work as well.
http://support.microsoft.com/kb/137890
I don't know it this is relevant but we are using a flag to the jvm so it does not shutdown on logoffs
"java -Xrs"
Link to suns description of -Xrs
I'm using Java Service Wrapper to start the java process as windows service.
I guess it works similary to the srvany.exe mentioned in the previous posting.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat / .exe as a System service with all the required call back methods to SCM.
Note :
1. Wrapping the process with 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).

Categories

Resources