I have a requirement to write a java program to remotely start stop a jboss server on request. Can anyone please suggest how could it be done? One option could be invoke start/stop script but this java program(may be servlet or jsp) exists on different machine. We are using jboss server 7.
You can stop JBoss EAP using the Management CLI or by pressing CTRL+C in the terminal. To stop JBoss EAP by pressing CTRL+C: Navigate to the terminal where JBoss EAP is running. Press Ctrl+C to stop JBoss Enterprise Application Platform.
2.3. To stop the server we can simply press “CTRL+C”. Additionally, jboss-cli could be utilized for issuing commands to the running instance of the server. For instance, we can use it to shut down the server.
A simple method to start and stopping Jboss remotely can be done with the run.sh and shutdown.sh script, by pointing to the right host and port. If you are on Linux you can run:
rsh user@host /path/to/jboss/bin/run.sh
rsh user@host /path/to/jboss/bin/shutdown.sh
You can also execute a Shell command with Java, you can use Runtime exec mewthod:
Runtime.getRuntime().exec("shell command here");
See this complete answer for more details on Java exec method.
A better alternative I would suggest, is to use JMX-console programmatically, you can stop/restart a Jboss intance by invoking the shutdown method on the Server MBean. JMX approach is more powerful because you can monitor and manage every aspect of the Jboss runinng instanace (like logging, memory or cpu). See this to start.
I've created a snippet to ease your start, see this working solution http://snipt.org/Ahhjh4
Remember:
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With