Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remotely start stop jboss server

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.

like image 388
user458580 Avatar asked Sep 30 '13 06:09

user458580


People also ask

How do I stop a JBoss server in terminal?

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.

How do I start and stop JBoss server in Unix?

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.


1 Answers

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:

  • create a Jboss user on the Jboss instance using add-user.sh (JBOSS_HOME/bin)
  • include the jboss-client.jar in your client class-path (the jar is in JBOSS_HOME/bin/client)

Good luck!

like image 176
zerologiko Avatar answered Sep 18 '22 11:09

zerologiko