DevOps Basics II: What is Listening on Open Ports and Files – WebLogic Essentials

Situation

who_is_listeningCan you easily find out which WebLogic servers are listening to which port numbers and addresses?

Imagine a multi-project machine with a dozen IPs and tens of domains. When trying to start WebLogic another process has already bound to the address and port so you get the following Java exception:

java.net.BindException: Address already in use

What is listening to a particular port on a certain IP?

Is it a WebLogic? If so, what is its domain name and directory?

Solution

There is a helpful UNIX command lsof (the name means “list open files”).

Description

Actually lsof is very versatile. Here are some examples of its usage.

Find what is listening on localhost and port 7001 on the local machine.

$ lsof -i @localhost:7001

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

java    2802 oracle  397u  IPv6  37417      0t0  TCP ccloud:afs3-callback (LISTEN)

You can tell from the output it is a Java process with PID 2802. To find out more about the Java process, (is it really WebLogic or maybe the Derby database or node manager using a weird port number?) narrow it down with ps.

 

$ ps -ef | grep 2802

 

oracle    2802  2746 18 10:40 pts/2    00:03:10 /usr/java/jdk1.7.0_04/bin/java -client -Xms256m -Xmx512m … .
-Dweblogic.Name=AdminServer … weblogic.Server

Looking at -Dweblogic.Name=AdminServer in the output above tells you it is a WebLogic admin server running. Now if you’d followed recipe 7 you could determine from the username the name of the WebLogic domain. Then you could conclude the domain directory from the domain name.

Discover Domain Name and Directory

Even if you didn’t follow recipe 7 with regard to users and names, there is still a solution. Here comes another trick with lsof (this is why I mentioned that it is so versatile!).

You can still find out what domain the WebLogic instance belongs to by looking at the files it has opened. In particular, you want to see the log files it has opened, because they belong to the domain and unveil the domain directory.

$ lsof -p 2802 | grep ‘\.log’

The last line in the output looks as follows:

java    2802 oracle  348w   REG      253,0        0 261838 /u01/domains/surfandconsulting/servers/AdminServer/logs/access.log

You can easily narrow down the grep command above if you know that your domain directory contains e.g. the word “domain”.

 

Process holding a file

You can also do it the other way around. Find out which process has a particular file opened.

$ lsof /domains/surfandconsulting/servers/AdminSrv/logs/access.log

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME

java    2802 oracle  348w   REG  253,0        0 261838 /domains/surfandconsulting/servers/AdminServer/logs/access.log

The output is telling you it is a Java process with process ID 2802, so you could use ps again to find out what exactly this Java process is.

 

 

Binding  to name

Check if WebLogic is listening to a particular name, e.g. the host name of the machine.

$ lsof -i @ccloud:7001

 

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

java    2802 oracle  397u  IPv6  37417      0t0  TCP ccloud:afs3-callback (LISTEN)

From the output you can tell it does!

Binding to IP address

Check if WebLogic is listening on the local machine to the address 192.128.9.1

$ lsof -i @192.128.9.1:7001

There is no output, so WebLogic is not listening to this address.

 

 

Hands-on Webcasts

I recorded a hands-on webcast available that walks you through the usage of lsof.

 

Oracle WebLogic Server 12c: Distinctive Recipes

Many more recipes are contained in my new WebLogic 12c book.

Comments

  1. Thank you.

  2. Srinivasan V says

    I do not have this command on my Linux box. Can someone tell me where I can download this tool.

    Thanks,
    Srini.

Trackbacks

  1. […] also check out the webcasts of the DevOps tools series about how to detect high CPU threads, or the usage of lsof. […]

Speak Your Mind

*