There are multiple answers to this, depending on what you mean by "running". For instance, @dogbane's answer tells you if a Tomcat process exists (modulo edge cases), and @Prabhakaran's answer tells you if Tomcat is listening on port 8080 (modulo different edge cases). But neither of these will pick up cases where Tomcat has stopped responding to requests.
@Elite's answer tells you if the default (e.g. ROOT) servlet is running, but this is probably not enough.
I'd recommend the following approach:
- Pick some webapp pages that you care about. Ideally these should include pages that depend on back-end services / databases.
- Create request URLs to fetch the pages, perform the queries, or whatever/
- Use
curl
or wget
to send the request URLs.
- Use some kind of pattern matching to make sure that you are getting good results and not error pages.
- If you get timeouts, unexpected response codes or error pages, crank out a mail message1.
This kind of thing is easier to do if you are running on a UNIX / Linux platform than on Windows because the tools you need to implement it should be either installed already, or easy to install using the package manager.
1 - Actually, that's a recipe for spamming yourself. A better idea is to deploy an event monitoring system that understands system states, does duplicate suppression and so on.