Question

I am not a programmer, but would like to know how the following task can be performed. I am working with an experienced developer and would like help from the programming community. If you can guide us or provide as a script, that will be awesome (and thank you ahead of time!)

Here is the scenario:

I have a JAVA application running on Tomcat 7 at Amazon's cloud EC2 instance (Linux).

I do not want any downtime for the web application (or very little).

What I want is if the web application crashes due to any reason, for it to get auto-restarted immediately as I try to find the cause of the crash.

Please note the scenario that we are trying to deal with: Tomcat is still running, but the web application is down. So you can't check for Tomcat being down as a parameter to restart the application

Was it helpful?

Solution

I don't know enough about EC2 to fully answer this (and I only have a few minutes before work) but if it's running in a scriptable environment and you can setup a cron job, it should be pretty easy.

  1. Have your app serve up a page with some XML or JSON that is parseable. This technique is commonly called a "canary" page -- like a canary in the mine (detects gas and dies first kind of deal)
  2. Create a script that accesses the canary page using curl or wget or something. If the response fails (aka your app is down), restart tomcat (or kill tomcat and start it again if it's still running, which it sounds like it will be)
  3. Set the job to run every minute or so via cron

Obviously, your best option is to write an app that doesn't crash :) But in the meantime, that could help and a canary page with some of your app's configuration info is generally very useful.

Sorry I don't have in depth details, but maybe some others could post in on the comments (or I will when I get back from work)

Also, Tomcat / Java EE offers a ton of bullet proof error handling so it should be rare that your app goes down. Are you sure your developer knows what he's doing?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top