I have found that I cannot connect to the tomcat shutdown port remotely.
Using code highly leveraged from the tomcat source, I wrote a simple java
app to issue the shutdown command to a given server and port #.  It only
seems to work if I use "localhost" as the server name.  If I try to use the
hostname or the fully qualified host name (even of the local system) it will
fail.  I have tried using this to stop Tomcat on linux and Windows XP with
the same results.  I have included the output I get when I run it and the
source code.  Any help understanding this would be greatly appreciated.
 
-------------------------Sample output--------------------------------
Attempting to shut down the tomcat server on ovwpc574/15.27.245.212 using
port 8085
 
tomcat_stop: java.net.ConnectException: Connection refused
java.net.ConnectException: Connection refused
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
            at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
            at java.net.Socket.connect(Socket.java:425)
            at java.net.Socket.connect(Socket.java:375)
            at java.net.Socket.<init>(Socket.java:290)
            at java.net.Socket.<init>(Socket.java:146)
            at tomcat_stop.main(tomcat_stop.java:40)
-------------------------End of Sample
output--------------------------------
 
-------------------------Source Code--------------------------------
import java.io.*;
import java.io.IOException;
import java.net.Socket;
import java.net.InetAddress;
 
 
class tomcat_stop
{
 
            public static void main( String [] args ) 
            {
                        int port_number;
                        InetAddress server_address=null;
                        Socket socket;
 
                        if (args.length != 2)
                                    usage();
                        
                        port_number = Integer.parseInt(args[1]);
 
                        try
                        {
                                    server_address =
InetAddress.getByName(args[0]);
                        }
                        catch (IOException e)
                        {
                                    System.out.println("");
                                    System.out.println("Unable to get
InetAddress using getByName on " + 
                                                            args[0]);
                                    System.out.println(":tomcat_stop " + e);
                                    e.printStackTrace(System.out);
                                    System.exit(1);  
                        }
 
                        // Stop the existing server
                        try {
                                    System.out.println("\n\nAttempting to
shut down the tomcat server on " + 
                                                server_address + " using
port " + port_number + "\n\n");    
 
                                    socket = new Socket(server_address,
port_number);
                                    OutputStream stream =
socket.getOutputStream();
                                    String shutdown = "SHUTDOWN";
                                    for (int i = 0; i < shutdown.length();
i++)
 
stream.write(shutdown.charAt(i));
                                    stream.flush();
                                    stream.close();
                                    socket.close();
                        }
                        catch (IOException e)
                        {
                                    System.out.println("tomcat_stop: " + e);
                                    e.printStackTrace(System.out);
                                    System.exit(1);
                        }
            }
 
            public static void usage()
            {
                        System.out.println("\nUsage:\n\ttomcat_stop <system
name> <port>\n\n");
                        System.exit(1);
            }
}
 
 


Reply via email to