Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have installed Monit using the following command in Ubuntu Linux 12.04.1 server

sudo apt-get install monit

My main goal in using Monit is to restart my - MySQL and Apache tomcat services automatically when they are killed/stopped.

#Check and restart mysql service
check process mysqld with pidfile "/run/mysqld/mysqld.pid"
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout

The above code works perfectly and Monit restarts MySQL service (when its killed/stopped).

I have actually configured tomcat as follows: - Downloaded the tomcat zip and extracted to a particular location - Configured this as my daemon service (and my tomcat server works properly).

As I don't have pid file for this tomcat setup, I am planning to check tomcat's status and start it using the following code:

#Check and restart tomcat service
check host tomcat with address 127.0.0.1
stop program = "/etc/init.d/tomcat stop"
start program = "/etc/init.d/tomcat start"
if failed port 8080 and protocol http
then start

However, I was unable to start tomcat successfully (when its killed). On investigating the Monit logs I found the following message:

[UTC Dec 24 12:08:23] error    : 'tomcat' failed, cannot open a connection to INET[127.0.0.1:8080] via TCP
[UTC Dec 24 12:08:23] info     : 'tomcat' start: /etc/init.d/tomcat

Through above logs, I found Monit is trying to start tomcat automatically for every particular time (when it finds tomcat service was killed). However, some inner conflicts stops this!

Other Information:

Tomcat server is properly running by using the port 8080:

netstat -an | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN     
tcp6       0      0 127.0.0.1:8080          127.0.0.1:53582         TIME_WAIT  


ps -ef|grep tomcat
root     16237     1  9 12:10 ?        00:00:37 /usr/lib/jvm/java-6-oracle/bin/java -Djava.util.logging.config.file=/usr/share/apache-tomcat-7.0.40/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1530m -XX:NewSize=512m -XX:MaxNewSize=1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -Djava.endorsed.dirs=/usr/share/apache-tomcat-7.0.40/endorsed -classpath /usr/share/apache-tomcat-7.0.40/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.40/bin/tomcat-juli.jar -Dcatalina.base=/usr/share/apache-tomcat-7.0.40 -Dcatalina.home=/usr/share/apache-tomcat-7.0.40 -Djava.io.tmpdir=/usr/share/apache-tomcat-7.0.40/temp org.apache.catalina.startup.Bootstrap start
root     16851 16847  0 12:17 ?        00:00:00 sh -c su root -c ps\ \-ef\|grep\ tomcat 2>&1 2>/dev/null
root     16852 16851  0 12:17 ?        00:00:00 su root -c ps -ef|grep tomcat
root     16853 16852  0 12:17 ?        00:00:00 bash -c ps -ef|grep tomcat
root     16855 16853  0 12:17 ?        00:00:00 grep tomcat

Adding preferIPv4Addresses and preferIPv4Stack in catalina.sh file:

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1530m
-XX:NewSize=512m -XX:MaxNewSize=1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"

Monit log:

[UTC Dec 24 12:48:39] error    : 'tomcat' failed protocol test [HTTP] at INET[127.0.0.1:8080] via TCP -- HTTP: Error receiving data -- Resource temporarily unavailable

Can anyone please guide me on this?

Thank You.

share|improve this question
    
Are you sure Tomcat is listening on 127.0.0.1 on your system ? Can you check this with netstat -an | grep 8080 ? –  krisFR Dec 24 '13 at 12:21
    
Thanks for the reply. I have edited my question and provided the netstat output (under 'Other Information:') –  Kamal Dec 24 '13 at 12:25
    
Strange...it seems that Tomcat has bound itself to an IPv6 address. telnet 127.0.0.1 8080 fails or not ? –  krisFR Dec 24 '13 at 12:31

1 Answer 1

Seems that Tomcat binds itself to an ipv6 address for 127.0.0.1.

You can try to use preferIPv4Stack=true and preferIPv4Addresses=true directives in Java options to bind to an ipv4 address

Edit catalina.sh Tomcat startup script and add the following :

JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"
share|improve this answer
    
Sorry, it doesnt works for me! I have editted the question with my results –  Kamal Dec 24 '13 at 12:49
    
Still does not work but not the same error message. So now what reports netstat -an | grep 8080 ? and telnet 127.0.0.1 8080 ? –  krisFR Dec 24 '13 at 13:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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