1

I am running 3 instances of a web crawler(Java program) in 3 Windows machines residing on the same network.

I want to write a master java program that monitors all the 3 web crawler programs and if any program is terminated, then it restarts that particular program.

I am able to bind the java program on the client machines to a socket and monitor the socket from the server, but I don't know how to restart the program if it terminates. I do not have even the slightest idea, how I am supposed to achieve this. Any guidance is appreciated.

How can I restart the client application remotely?

Dzyann
  • 5,062
  • 11
  • 63
  • 95
CoralReef
  • 61
  • 1
  • 7
  • What are you trying to achieve here? Are you going to write some sort of malware? – Binkan Salaryman May 28 '15 at 11:19
  • [Add a JVM shutdown hook][1] and restart your program as a new process. [1]: http://stackoverflow.com/questions/9317461/get-the-application-closing-event – Binkan Salaryman May 28 '15 at 11:22
  • I think the question is too broad. You can use some sort of a supervisor (either written by you or a 3rd party, like http://stackoverflow.com/questions/7629813/is-there-windows-analog-to-supervisord) that monitors the processes locally and restarts them if needed. You can make it accessible remotely (server, messaging). In any case you need something external to the Java processes you want to start. Another option would be to run a command in command-line remotely. Look up how to do it on Windows, most likely you'll have to enable a protocol or install a software (SSH is just one option). – vempo May 28 '15 at 11:27
  • @BinkanSalaryman The hook will not be triggered, if the process simply hangs or dies unexpected. It will only kick in when the VM exits more or less planned. – thst May 28 '15 at 11:29
  • I achieved this task on linux using SSH client to programatically connect to server and restart the program on the slave server, it might worth looking at some windows SSH server. – nafas May 28 '15 at 11:30

1 Answers1

1

Obviously, you need another component on the remote server to run the dead Java app.

You can utilize PsExec to run the remote crawler when you find it dead.

https://technet.microsoft.com/de-de/sysinternals/bb897553.aspx

The tasklist command can list the tasks on a remote machine, so you can create your own "nagios"-very-light-edition.

tasklist /S computer should list the tasks on the remote system "computer".

If this is a serious, professionally sold, not only inhouse solution, you need to invest in a control-program for the remote task and possibly decide to run the crawlers inside an application server or similar runtime. This way, you have far more control over the currently running version etc. Distribution of updates will be easier and you can use well known monitoring systems to remote-check the state of the crawler.

thst
  • 4,592
  • 1
  • 26
  • 40