Skip to content
Damianofds edited this page Dec 5, 2012 · 1 revision

The watchdog are simple bash scripts used to automatic check the status and restart a web service (usually tomcat).

How the watchdog works

These scripts should be used with a compliant tomcat service since its the output is used to get the pid of the process.

It simply try to download a file using the specified url with specified timeout, if the response is an error (see 'man wget') then the service is restarted. Script Note

Using cron to schedule the script

NOTE: seconds (TOMCAT_TIMEOUT x RETRY) MUST be smaller than the cron interval

In crontab you have to specify 5 time parameters in order to schedule the script executions.

  1. m min (0 - 59)
  2. h hour (0 - 23)
  3. dom day of month (1 - 31)
  4. mon month (1 - 12)
  5. dow day of week (0 - 6) (Sunday=0)

Example run /var/lib/tomcat/geoserver/bin/watchdog.sh every 30 minutes:

root@buddata:/home/geosolutions# cp /home/geosolutions/watchdog.sh $CATALINA_BASE/bin/

root@buddata:/home/geosolutions# chmod +x $CATALINA_BASE/bin/watchdog.sh

root@buddata:/home/geosolutions# crontab -e

$# m h dom mon dow command

*/30 * * * * /var/lib/tomcat/geoserver/bin/watchdog.sh

  • be shure cron is started

  • Some of the used variables need changes!

  • Always test the requested URL and the FILTER manually (look into the code for the URL and FILTER variables)

  • Due to the script batch nature it do not support arguments, set variable accordingly before start this script

  • This script should be started by the user which is able to use services (usually root)

  • This script expect some output printed on the stdout (this is done to get the PIDFILE of the process)

---------------------Expected output example:----------------------

apache-tomcat-6.0.24# bin/shutdown.sh

Using CATALINA_BASE: /var/lib/apache-tomcat-6.0.24

Using CATALINA_HOME: /var/lib/apache-tomcat-6.0.24

Using CATALINA_TMPDIR: /var/lib/apache-tomcat-6.0.24/temp

Using JRE_HOME: /usr

Using CLASSPATH: /var/lib/bin/bootstrap.jar

PID file (/var/lib/catalina.pid) found but no matching process was found. Stop aborted.

--------------------------------------------------------------------------------

this is the standard message printed by the tomcat shutdown.sh script.

NOTE: the pid file has an absolute path (set it into the setenv.sh or elsewhere)

8- remember manually create the output file otherwise the script will print on the stdout

9- remember to logrotate the output file of the watchdog script

Requirements

  • gawk

  • bash

  • wget

  • expr

Clone this wiki locally