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
link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

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.

link|improve this answer
Thanks !!! Any idea catalinamonitor would create automcaticaly? If so at which case – Selvakumar P Feb 20 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 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 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 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 at 4:26
show 1 more comment
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.