简体   繁体   中英

How to launch java program from management application using JMX

Assume I have a java program packaged in a executable jar which I normally start from the command line using java -jar myappjar.jar. Now I want to develop remote management application to launch this java program and also once launched I want to be able to stop it by which I mean it must call a method shutdown in my program which will do clean up work and exit the program.

Also when I launch the remote management application itself, it should tell me if the program I want to launch is already running, if so then stop it first.

Is all of above possible and how to achieve that ? Especially the most important is to be able to launch the program that is not running already.

The program that I launch is a server that keeps running forever until shutdown either manually or via remote management application. This server should in no way depend on JMX Agent or remote management application ie remote management application/JMX agent can be shutdown and server program still keeps running or server can be manually launched and later remote management application can be started to instrument this server program if so desired.

What you actually need is a some kind of Management agent :

A Management agent is a software agent that runs on a managed node and provides an interface to manage it. It can perform operations on managed objects in the node and can also forward notifications to the manager.

Please see an example:

在此输入图像描述

In your case it will be a JMX protocol between Management tool and applications. It is a precondition to have an Agent up and running on a remote host. It doesn't seem to be a hard task to develop a basic agent, capable of the following:

  • download/deploy an application
  • start/stop the application
  • monitor deployed application

Agent is a very simple application with several commands (management actions) implemented.

在此输入图像描述

Useful link: Agents in Network Management

Update: glu agent example

glu is a free/open source deployment and monitoring automation platform. Glu is solving the following problems:

  • deploy (and monitor) applications to an arbitrary large set of nodes:
  • efficiently
  • with minimum/no human interaction
  • securely
  • in a reproducible manner

It is based on the same principle and has an agent in it:

The glu agent is an active process that needs to run on every host where applications need to be deployed. Its main role is to run glu scripts. It is the central piece of the deployment automation platform and is the only required piece of infrastructure. It exposes a REST api and a command line (which invokes the REST api under the cover).

Feel free to ask if you need some additional comments.

Maybe I don't understand the question well, but JMX is just used to control your management application and it is somehow not relevant to problem of starting or stopping your application, isn't it?

Basically you can start new Process to execute java -jar myappjar.jar from your management application (eg via Runtime.exec() ) Since you want controlled shutdown, you need kind of inter-process communication, so that your management application can shutdown your application, eg by sockets. This can be later on used also for "running" detection.

Jenkins is a java based Continuous Integration Server which can launch applications remotely. You may check its source code for ideas.

For UNIX machine based setups, it uses SSH based approach (probably jsch )

Jenkins manages windows remoting using j-interop .

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