tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Java programm to Shutdwon the tomcat server
Date Mon, 01 Mar 2010 20:00:22 GMT
dBenjamin wrote:
> Thanks for helping...
> Can you please find my scenario?

We could probably help better if we understood exactly what you are
trying to achieve (and why), which is not very clear at the moment.

> 1.	I am using windows Environment.

Ok, but are you running Tomcat as a Windows Service, or as an
application in a command window ?

If you are running Tomcat as an application in a command window, then
when the user who started Tomcat logs off, Tomcat will stop.

> 2.	I am using tomcat 6 binary distribution versions here we cannot get pid
> from the windows.

I do not understand why not.
Try the command "netstat -b" and look at the last column. It shows the 
pid of the process using each port.
Look at the help for the netstat command for more options.

> 3.	For my requirement before starting the tomcat server I need to verify the
> port availability if any other application using then I have change both
> shutdown port and http port. 

One way to do this (maybe the only way) is to change the
(tomcat_dir)/conf/server.xml file, *before* starting Tomcat.
You cannot start Tomcat and change these ports afterward.
It is too late then, because Tomcat will already have tried to open
these ports, and fail to start if they are already in use.

  I facing problem to change the port address, I
> am validating shutdown port using socket

what do you mean ?

  and http port using
> package. 

what do you mean ?

All you need to know, before starting Tomcat, is if these ports are 
already in use. You can do that with the same method for both ports. 
There is no reason to use a different mechanism for each port.

Maybe have a look at this :

*Before* you start Tomcat, open a Windows command window.
Let's call this "window A".
In window A, run the command

netstat -abn -p TCP

and read the lines that are output by that command.
The lines which have "LISTEN" in it are the interesting ones. They show 
what listening ports are already used, and by which process.

2) Now open another command window B, and go to the top directory where 
you installed Tomcat (for example, c:\apache-tomcat-6.0.24).
Then start Tomcat, using the command :
Tomcat should start, in a 3rd command window C.

3) Now, in the command window A, enter the same command again :
netstat -abn -p TCP
Now you should see 2 additional LISTEN ports, and you should see that 
they are "used" by the process which runs Tomcat. You should see 2 lines 
like this :
TCP   ABHÖREN    1164 [java.exe]
TCP ABHÖREN    1164 [java.exe]

(instead of ABHÖREN, you will see LISTEN, if your Windows speaks English)
In my case, the shutdown port of Tomcat is 8005, and the HTTP port is 
8080. That is why I get the 2 lines above.

4) By default, the Tomcat shutdown port is 8005, and the shutdown string 
So now, in the same window A, enter this command :
telnet localhost 8005

and you should get a new line. On this new line, type
(in capitals, and you will not see it on the screen, because Tomcat does 
not echo this)
If you finish this line by the <CR> key, you will see the Tomcat running 
in Windows C shutting down (and window C will close).


It would be better if you tried to explain what you want to do and why 
you want to do that.  Do not explain how you want to do it, let us 
suggest a way.

But now I will try to guess what you want to do, and trying to recommend 
a way of doing it.

- you want to start Tomcat, and you want to make sure that it starts.
For that, you need to be sure that the ports which Tomcat needs to open, 
are not already used by something else.
- and after Tomcat is started, you want to be able to shut it down 

So, do as follows :
- create a standard server.xml file for Tomcat, which uses port 8005 for 
the shutdown, and 80 for the HTTP port
- use the command
netstat -abn -p TCP
to find out if the ports 8005 and 80 are "free".
If yes, you can start Tomcat "as is".
- if not, you have to modify the server.xml file to use 2 ports that are 
free, and *then* start Tomcat.
- when Tomcat is started, note the port finally chosen for the shutdown port
- then do whatever you want to do with Tomcat
- to stop Tomcat, open a TCP socket connection to localhost:xxxx (where 
xxxx is that shutdown port), send the string "SHUTDOWN" on that 
connection, followed by a CR/LF port. Then close this socket.
This should be enough to shut down Tomcat.

It will be different if Tomcat is running as a Windows Service.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message