Tomcat – Cannot ping Localhost so I can’t shutdown Tomcat

tomcattomcat6

I installed Tomcat 6 using the tar-ball via wget. Startup of the server is fine but on shutdown I get a timeout exception.

root@88:/usr/local/tomcat/logs# /usr/local/tomcat/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar
30-Mar-2010 17:33:41 org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop: 
java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    ...

I read that this might be because I have a firewall blocking incoming connections on the shutdown port (8005). I have a default Ubuntu 9.04 installation running on a VPS with no rules in my iptables. How can I tell if that port is blocked? How can I check that the server is listening for connections on 8005?

Bizarrely pinging localhost or the IP of my server fails from the server itself, whereas pinging the IP of my server from another machine succeeds.

——– EDIT ——–
(In reply to Davey)

Thanks for all the tips and suggestions!

netstat -nlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      9611/java       
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      28505/mysqld    
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      9611/java       
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      

So we can see that tomcat is listening, I just don't seem to be able to reach it.

root@88:/usr/local/tomcat# telnet localhost 8005
Trying 127.0.0.1...

Trying to telnet to the port Hangs indefinitely. I have no rules in my iptables so I don't think it's a firewall thing.

root@88:/usr/local/tomcat# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

This is the contents of /etc/hosts

127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
88.198.31.14 88.198.31.14  88 88

But I still can't ping localhost… do I need to check a loopback device is enabled properly or something? (I'm unsure how to do that if you do say yes :)).

root@88:/usr/local/tomcat# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.

--- localhost ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 5999ms

Trying to find out what the loop back is configured as;

root@88:~# ifconfig lo
lo        Link encap:Local Loopback  
          LOOPBACK  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

SOLUTION THANKS TO DAVEY

I needed to bring up the interface (Not sure why it wasn't running). ifconfig lo up did the trick.

root@88:~# ifconfig lo up
root@88:~# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@88:~# ping localhost
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.025 ms

Thanks again,

Gav

Best Answer

The command netstat -nlp will show you what is listening:

]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address       Foreign Address    State       PID/Program name   
tcp        0      0 127.0.0.1:8005      0.0.0.0:*          LISTEN      13940/java          
tcp        0      0 0.0.0.0:8009        0.0.0.0:*          LISTEN      13940/java          
tcp        0      0 0.0.0.0:8080        0.0.0.0:*          LISTEN      13940/java          
tcp        0      0 0.0.0.0:22          0.0.0.0:*          LISTEN      3377/sshd   

The lsof command on the pid of the tomcat process will show something similar:

java    13940 root   35r   CHR    1,9              942 /dev/urandom
java    13940 root   36r   CHR    1,9              942 /dev/urandom
java    13940 root   38u  IPv4  31050              TCP *:8009 (LISTEN)
java    13940 root   39u  IPv4  31053              TCP 127.0.0.1:8005 (LISTEN)

When you run shutdown.sh you should see traffic go to port 8005:

[root@test001 ~]# tcpdump -i lo 'port 8005'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
20:11:22.168395 IP test001.36696 > test001.8005: S 2859727005:2859727005(0) win 32792 <mss 16396,sackOK,timestamp 20428874 0,nop,wscale 7>
20:11:22.168922 IP test001.8005 > test001.36696: S 2855491174:2855491174(0) ack 2859727006 win 32768 <mss 16396,sackOK,timestamp 20428874 20428874,nop,wscale 7>
20:11:22.168598 IP test001.36696 > test001.8005: . ack 1 win 257 <nop,nop,timestamp 20428874 20428874>
20:11:22.171127 IP test001.36696 > test001.8005: P 1:2(1) ack 1 win 257 <nop,nop,timestamp 20428877 20428874>
20:11:22.171144 IP test001.8005 > test001.36696: . ack 2 win 256 <nop,nop,timestamp 20428877 20428877>
20:11:22.171443 IP test001.36696 > test001.8005: P 2:3(1) ack 1 win 257 <nop,nop,timestamp 20428877 20428877>
20:11:22.171453 IP test001.8005 > test001.36696: . ack 3 win 256 <nop,nop,timestamp 20428877 20428877>
20:11:22.171686 IP test001.36696 > test001.8005: P 3:4(1) ack 1 win 257 
  1. Check that localhost resolves e.g. it's in /etc/hosts.
  2. Check that you are not running the Ubuntu Firewall.
  3. Post your netstat -nlp output if you can.
  4. Try telnet localhost 8005 or telnet 127.0.0.1