简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM