2

We have a script like below to monitor our server. During this code our server getting restarted. Can anyone please explain the meaning of below script?

if [ -f $HOME/catalinamonitor ]; then
  echo JVM failed;
  export JAVA_HOME=/usr/java/jdk1.6.0
  $HOME/jakarta-tomcat/bin/shutdown.sh
  sleep 30
  /usr/bin/killall -9 java 2>/dev/null
  $HOME/jakarta-tomcat/bin/startup.sh
  rm -f $HOME/catalinamonitor
  exit 1
fi
Selvakumar P
  • 305
  • 2
  • 8
  • 16

2 Answers2

2

If the file $HOME/catalinamonitor exists, write JVM failed to the screen. Put the value /usr/java/jdk1.6.0 in JAVA_HOME and make it an environment variable.

Run the script in $HOME/jakarta-tomcat/bin/shutdown.sh, wait 30 seconds and kill all processes that are java. All output will be redirected to /dev/null (not shown on screen).

Run the following script $HOME/jakarta-tomcat/bin/startup.sh and delete the file rm -f $HOME/catalinamonitor. Terminate the script with an error (1).

So basically, If a file exists, kill all tomcat and java, then restart it and delete the file.

Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
  • Thanks !!! Any idea `catalinamonitor` would create automcaticaly? If so at which case – Selvakumar P Feb 20 '12 at 12:16
  • Probably it's a file created by another script after doing a check (probably some sort of check on the tomcat-server). Maybe something in the same script? – Bart De Vos Feb 20 '12 at 13:36
  • the script file has like this `touch $HOME/catalinamonitor`, this executes every 10 mins. Apart from this we dont have anything related to catalinamonitor – Selvakumar P Feb 20 '12 at 13:42
  • And when does it do the `touch $HOME/catalinamonitor`? That is when the script says it's necessary to restart the tomcat-server. – Bart De Vos Feb 20 '12 at 13:46
  • The first part of the script is what I have mentioned in the question, Second part has touch command. Both are in same script file which will be excuted every 10 mins as set in cron job – Selvakumar P Feb 21 '12 at 04:26
  • Then it's basically telling to restart the service every 10 minutes. IF you want to get rid of it, remove the `touch`-command. – Bart De Vos Feb 21 '12 at 07:49
2

A way better solution is to use YAJSW or similar as a watchdog. I cringed at the killall...

pyroscope
  • 231
  • 1
  • 3