1

I have a java application which I run using yasjw tool as a daemon. I need to monitor it in case it goes down I need some kind of alert or even restart it. Is there any tool can help me do this on centos environment?

The results of ps -ef | grep java

root      3109     1  0 Apr06 ?        00:04:35 /usr/java/jdk1.6.0_18/bin/java -Dwrapper.pidfile=/var/run/wrapper.commServer.pid -Dwrapper.service=true -Dwrapper.visible=false -jar /usr/local/yajsw-beta-10.2/wrapper.jar -c /usr/local/yajsw-beta-10.2/conf/wrapper.conf
root      3132  3109  0 Apr06 ?        00:25:26 /usr/java/jdk1.6.0_18/bin/java -classpath /usr/local/yajsw-beta-10.2/./wrapperApp.jar:/usr/local -Xrs -Dwrapper.service=true -Dwrapper.console.visible=false -Dwrapper.visible=false -Dwrapper.pidfile=/var/run/wrapper.commServer.pid -Dwrapper.config=/usr/local/yajsw-beta-10.2/conf/wrapper.conf -Dwrapper.port=15003 -Dwrapper.key=4276015160565963367 -Dwrapper.teeName=4276015160565963367$1333699547154 -Dwrapper.tmpPath=/tmp org.rzo.yajsw.app.WrapperJVMMain
root     23986 23945  0 16:53 pts/0    00:00:00 grep java

pidof java
3132 3109
user111196
  • 1,257
  • 2
  • 13
  • 14

1 Answers1

1

use monit http://mmonit.com/monit/

chocripple
  • 2,109
  • 14
  • 9
  • so inorder for me to run monit must I monitor the yajsw or the java application itself? – user111196 Feb 22 '12 at 03:32
  • cmiiw, i think the java process. you may customize http://fak3r.com/2010/10/07/howto-monitor-tomcat-with-monit-and-munin-in-debian/ or some examples from the site http://mmonit.com/wiki/Monit/ConfigurationExamples – chocripple Feb 22 '12 at 03:47
  • after reading the links you gave me looks like I do not need the yajsw tool is it to run it as a daemon is it? Can monit run the java applicatio as daemon? – user111196 Feb 22 '12 at 04:09
  • monit only daemon that can monitor process, and there is feature on monit that you can do like restart the service if the process is down (you need specify the command) – chocripple Feb 22 '12 at 04:22
  • i read on yasjw there is feature "Monitor and automatically restart hanging or crashed proceses" http://yajsw.sourceforge.net/#mozTocId113692 – chocripple Feb 22 '12 at 04:29
  • nvm let me do more readings then get back to you – user111196 Feb 22 '12 at 04:31
  • In general, you should avoid creating answers that are just a link. See How To Answer: http://serverfault.com/questions/how-to-answer. That being said, Monit is pretty cool. – Kyle Smith Feb 22 '12 at 04:56
  • @rikih yes the feature at times does not work in full it will keep restarting the java and will give up after certain number of tries. – user111196 Feb 22 '12 at 05:00
  • @rikih ok I have set centos 6.2 machine. I have gone this site http://pkgs.repoforge.org/monit/ and two files RHEL6 and CentOS-6 x86 64bit and Distribution independent source. I tried yum install monit it say no package to install. – user111196 Feb 26 '12 at 02:08
  • 1
    on pkgs.repoforge.org/monit there are monit-5.2-1.el6.rf.i686.rpm and monit-5.2-1.el6.rf.x86_64.rpm, just download and rpm -ivh monit-xx.rpm – chocripple Feb 26 '12 at 03:44
  • @rikih isnt those are very old version right? They have the latest version right? Any reason for the old version? – user111196 Feb 26 '12 at 05:43
  • @rikih I have run the command you gave so what is next step? It showed me 1:monit ########################################### [100%]. – user111196 Feb 26 '12 at 05:51
  • pls try to use the sample config in http://mmonit.com/wiki/Monit/FAQ check process xyz with pidfile /var/run/xyz.pid start = "/bin/xyz start" stop = "/bin/xyz stop" the wrapper on the url – chocripple Feb 26 '12 at 16:02
  • in my case i use tomcat e.g: check host tomcat with address 127.0.0.1 if failed port 8080 send "HEAD / HTTP/1.0\r\n\r\n" expect "HTTP/1.1" with timeout 5 seconds then exec "/usr/local/sbin/tomcat-restart" – chocripple Feb 26 '12 at 16:04
  • @rikih ok I did this pgrep java 709 2803 I guess one should be the java itself and the other should be the yajsw? – user111196 Feb 26 '12 at 16:56
  • @rikih so in my case there is pid so what should I do. For it to email must I setup my own email server is it? – user111196 Feb 27 '12 at 03:53
  • either you monitoring java only or yajsw. cmiiw, in this case you are using yajsw for daemon, so just use yajsw PID for monitor in monit, put the start/stop command yajsw. email is for alert, who will receive it in case any events. – chocripple Feb 27 '12 at 04:03
  • @rikih what about going for the java application itself because I have experience at times the yajsw is running but the java is not running. Or shall we monitor both wouldnt that be better? – user111196 Feb 27 '12 at 16:33
  • hmm i think better the java it self, you may use the sample config in http://mmonit.com/wiki/Monit/FAQ there is the wrapper script for java. – chocripple Feb 28 '12 at 06:13
  • @rikih ok I have read through the sample it this check process xyz with pidfile /var/run/xyz.pid. So the process xyz is my class name is it? Then in my case I put my file in /usr/local/com1000. So where must put for the line pidfile? – user111196 Apr 07 '12 at 12:47
  • xyz is your jar file. you may put the pid on /var/run/xyz.pid, it will generated on the script "echo $$ > /var/run/xyz.pid;" – chocripple Apr 08 '12 at 05:44
  • @rikih I have updated my post with the results of ps -ef | grep java. So there are two pid which I guess one is for my java and another is for the wrapper right? I dont have .jar file so what to put in te /var/run/xyz.pid? – user111196 Apr 08 '12 at 09:18
  • hmm i thought your java app is jar file. please refers to http://pastebin.com/DgZiCStq . since you have your wrapper already you just use pid from your wrapper. and if needed you can monitor your app via accessing the url (if any). – chocripple Apr 08 '12 at 13:24
  • Mine is just .class file only. Ok I saw the codes quite understand it too. First line you check rite "check process inetd with" whether there is pid for wrapper.commServer.pid. Then if none you do a start is it but then there is also a stop there? How this comes into play if failed port 8080 protocol HTTP. – user111196 Apr 08 '12 at 14:45
  • if you just put pid only, monit will just check if the pid still on process table or not, and you also can use check port 8080 (tomcat/jboss/etc) if it's running, it's another check option only, you may remove it if you don't want to use it. start and stop are the command monit will use to manage the service. – chocripple Apr 08 '12 at 15:25
  • @rikih ok good idea yes actually my java is socket connection listening on port 9000. So then I should include it too. I want to understand first this part "check process inetd with" you just do a check here rite. Then if is not there then you do a start is it then why you have stop on the next line. Sorry I am new to this tool. – user111196 Apr 08 '12 at 15:29
  • @rikih I have tested it will try and try then just give up. So I want some thing where it will try and it really cant then at least maybe notify me. – user111196 Apr 08 '12 at 15:35
  • the configuration is not like program that read from top to bottom, it's just definition. may be you will be clear on http://pastebin.com/VaUehpnY , inetd is the program name, it was typo you can use anything. – chocripple Apr 08 '12 at 15:41
  • @rikih ok I can see it now you added more comments rite. So when will it stop and start? First line just do a check if there is process id still alive what is after that? – user111196 Apr 08 '12 at 15:59
  • if the pid alive on process table, monit will not restart. if pid is alive and port 9000 cannot accessible, monit will restart. if it's repeat 5 times, then monit will not try restart anymore. – chocripple Apr 09 '12 at 01:06
  • @rikih this is how their logic is written is or shell scripts? Anyway so after 5 times what normally you suggest to do email is it? – user111196 Apr 09 '12 at 04:02
  • you may refers to configuration examples on http://mmonit.com/monit/documentation/monit.html. yeah set alert to send email if it's failed after 5 times, how to set please see http://www.debian-administration.org/articles/269 – chocripple Apr 09 '12 at 05:04
  • @rikih is it a must to have email server on the monit server itself? I am trying to read the links you gave me earlier. – user111196 Apr 09 '12 at 05:46
  • no need, you can specify the mail server using set mail-server http://mmonit.com/monit/documentation/monit.html#setting_a_mail_server_for_alert_messages – chocripple Apr 09 '12 at 07:09
  • @rikih ok I have tried I set the mail server, the receipt, the mail format. Then when I want to start there is not monitrc file so I change the .conf to monitrc and below is the results when I start /etc/init.d/monit start Starting monit: monit: Error opening the idfile '/var/monit/id' -- No such file or directory – user111196 May 12 '12 at 15:48