Reputation: 21371
We have a java application that's essentially a long running process. It's deployed on JBoss 6.1. We have to start it by going to the url http://ip.ip.ip.ip:8080/MyApp/Monitor
Is there a way we could run it as a service via the cli with some ability to start / stop / restart as needed?
Upvotes: 2
Views: 1713
Reputation: 29669
I would recommend using Apache Commons Daemon (or maybe YAJSW) to create your own wrapper controller class. An example of this is shown here. The wrapper controller extends the Daemon class of Commons-Daemon and it could be ran on the command line in the form of :
java -cp . WrapperController.class -windowsStop
java -cp . WrapperController.class -windowsStart
java -cp . WrapperController.class -verify
You could also of course, extend the example to have its own SysTray object. You could also implement your controller class as a Beanshell script so that it need not be a pre-compiled class to run.
Upvotes: 0
Reputation: 2348
If it is the only application running on the JBoss instance, you could configure your JBoss to automatically start you application when it starts and then follow the steps in http://community.jboss.org/wiki/JBossSystemService to run JBoss as a service.
If you have other applications on the JBoss instance or you want to start/stop only the application and not the whole server, you could write a Java application that connects to your JBoss instance remotely using Java Management Extensions and use the JMX Beans provided by JBoss to start/stop your application. More about JBoss JMX interface can be found in http://docs.jboss.org/jbossas/jboss4guide/r2/html/ch2.chapter.html I know this is of JBoss 4 but I don't think they dropped JMX support in newer versions.
Upvotes: 4
Reputation: 12538
Fire a call to your application directly from the console using the java
command.
Example:
public class MonitorService{
..
public static void main(String[] args) {
if(args[0].equalsIgnoreCase("-start")
{
//Do start routine
}
else if(args[0].equalsIgnoreCase("-stop")
{
//Do stop routine
}
}
...
}
Run the program as the follows.
Java MonitorService -start
Upvotes: 0
Reputation: 4723
Make it a console application?
public static void main(String [] args)
{
doStuffThatMyAppMonitorNormallyDoes();
}
Upvotes: 0