0

i want to set a script which will restart the server automatically.

And i write the following code to setenv.sh file

JAVA_OPTS="$JAVA_OPTS -XX:OnOutOfMemoryError=/usr/local/apache-tomcat-5.5.30/bin/shutdown.sh;/usr/local/apache-tomcat-5.5.30/bin/startup.sh;"

It not working properly. I am using tomcat 5.

Beryllium
  • 12,808
  • 10
  • 56
  • 86
user2739655
  • 141
  • 1
  • 3
  • 14
  • What do you mean by not working properly? Can you give a specific error? – Trisha Sep 02 '13 at 11:50
  • I am unable to restart the tomcat when OutOfMemoryError occure – user2739655 Sep 02 '13 at 13:19
  • What error do you get? Is there a message in the logs somewhere? – Trisha Sep 02 '13 at 14:49
  • java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: PermGen space This 2 error getting at-least in a day. And then i get http 500 error and then it tell me system is not accessible. And tomcat goes down – user2739655 Sep 03 '13 at 05:43

2 Answers2

0

To answer your question - I don't think the error handler can run several commands. If you want to do this, then write a small restart script and run your custom script.

However, I would think about this again. Not every OutOfMemoryError means the server should be restarted automatically. You'd better to get a notification and then profile the server to get the cause of the OOME, so you can get rid of it.

P.S Any reason to use the old tomcat 5.5? tomcat 7 is quite mature.

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
  • Hi thanks for help. can you tell me one thing we have 2 GB ram and our tomcat goes down at-least 1 time in a day. Only 50 user using it at a time. Can you help me? – user2739655 Sep 03 '13 at 10:34
  • First of all, check if the OOME of the heap or of the perm gen (it's in the log). If you an stand a few minutes of downtime (worst case) is to add the -XX:+HeapDumpOnOutOfMemoryError flag which will give an heap dump file automatically whom you can analyse using applications such as http://www.eclipse.org/mat/ – David Rabinowitz Sep 03 '13 at 17:42
0

Use CATALINA_OPTS instead

CATALINA_OPTS="${CATALINA_OPTS} -XX:OnOutOfMemoryError=\"/bin/sleep 30;/bin/kill %p; /bin/sleep 60; /bin/kill -9 %p\""
Himadri Mandal
  • 325
  • 2
  • 11