There is an MBean for the Server and I believe that you can specify the command 
there.

Oleg Lebedev <[EMAIL PROTECTED]> wrote:  
Great, sending that shutdown command to a Tomcat server started with
server.xml file on the disk worked.

But how can I specify what the server shutdown command is when I start
the server in embedded mode on a certain port? (See code below)


private static void startTomcat(){
String hostName = "localhost";
int port = 8888;

String commonPath = "C:/myapp";
String catalinaHome = commonPath + "/tomcat";
System.setProperty("catalina.home", catalinaHome);

Embedded embedded = new Embedded();

MemoryRealm memRealm = new MemoryRealm();
embedded.setRealm(memRealm);

Engine engine = embedded.createEngine();

Host host = embedded.createHost(hostName, "");
engine.addChild(host);
Context rootCtx = embedded.createContext("", "/");
rootCtx.setPrivileged(true);
host.addChild(rootCtx);
embedded.addEngine(engine);

Connector httpConnector = embedded.createConnector(
(java.net.InetAddress) null, port,
false);

embedded.addConnector(httpConnector);
embedded.start();
} 


-----Original Message-----
From: Iannis Hanen [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, December 14, 2005 5:35 PM
To: Tomcat Users List
Cc: Iannis Hanen
Subject: RE: starting and stopping Tomcat from Java code

Hi Oleg,

The piece of code you just mentioned is what lies behind the 
tag in the server.xml file. You can set the tag this way:



If you connect to port 1234 on the tomcat machine and type in the
"myShutdown" password, tomcat will shutdown. However, I am pretty sure
that this port is opened only for callers from localhost. So, if you
intend to stop it remotely, this may not be possible. You may have to
use a proxy of some kind to relay your call so that tomcat believes the
call comes from localhost.

Iannis

-----Original Message-----
From: Oleg Lebedev [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 4:27 PM
To: Tomcat Users List
Subject: RE: starting and stopping Tomcat from Java code

Thanks, Wendy.

I looked at cargo and it seems that it requires the container to be
installed on the local machine in order to be able to start or stop it.

In my case I have Tomcat running on some machine with a known IP address
and port number. I need to be able to send a shutdown command to that
Tomcat instance and have it stutdown itself.

I just noticed this piece of code in Catalina.stopServer(String[]):

Socket socket = new Socket("127.0.0.1",
server.getPort());
OutputStream stream = socket.getOutputStream();
String shutdown = server.getShutdown();
for (int i = 0; i < shutdown.length(); i++)
stream.write(shutdown.charAt(i));
stream.flush();
stream.close();
socket.close();

This may be what I need to use in my Java class to shut down the local
Tomcat instance.

Any ideas on whether this is the right way to shut down a stand-alone
Tomcat instance?

Thanks.

Oleg

-----Original Message-----
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 4:44 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code

On 12/14/05, Oleg Lebedev wrote:

> I am trying to configure, start and then shutdown Tomcat from my Java 
> class.

No idea if it will do what you want, but that requirement made me think
of Cargo:
http://cargo.codehaus.org/

--
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




                        
---------------------------------
Yahoo! Shopping
 Find Great Deals on Holiday Gifts at Yahoo! Shopping 

Reply via email to