May 25, 2012
tom

linux script – find java process and restart it if it is more than 80% Mem High

Question

I want to put in crontab a shell script that will monitor the java process and if it’s the memory is more than 80% then I want to restart it.
can any one help?
Thanks!!
Elad.

Asked by Elad Dotan

Answer

Perfect use case for monit.
http://mmonit.com/

Example Config


check process foo with pidfile "/var/run/foo"
start program = "/bin/foo -c foo.conf"
stop program = "/bin/kill -KILL
cat /var/run/foo.pid"
if totalmem is greater than X.0 MB for 5 cycles then restart

The reason you want monit rather than a script is that it can email you, provide logs, and honestly a lot more, but I’ll leave the research up to you.

Answered by foocorpluser

Related posts:

  1. Restart apache process using shell script cannot find apache
  2. Centos Linux monit configuration
  3. Why can’t I see the monit binary in the process list after starting it?
  4. Java process eating CPU; Why?
  5. Linux script to find time difference and send an email if need

Leave a comment