You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Olivier Lefevre <le...@yahoo.com> on 2011/02/28 16:34:56 UTC
Getting the Tomcat shutdown port
Is there a programmatic way to retrieve it from within
a webapp, more exactly from within Servlet.init()? I
can't find one. Same question for the actual command.
As you may have guessed, I want to shut down Tomcat by
opening a socket and sending it a SHUTDOWN or whatever.
Maybe there is a less low-level way to do it but I can't
find it either.
Thanks,
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
On 2/28/2011 6:09 PM, Caldarale, Charles R wrote:
> The servlet, or the webapp?
The webapp in this case: the servlet that might fail is the
"worker" servlet, the others more in a supporting role (e.g.,
UI). So if it fails the whole webapp should shut down.
> Why don't you simply throw a ServletException in the init()
> method of the servlets of interest?
OK. But how to communicate to the other servlets of the
webapp that they, too, should commit suicide?
Are they guaranteed to be created in a certain order? In that
case I'd put the worker servlet ahead and then maybe there is
a way to leave a breadcrumb behind after its death as a sign
to the others that they should not proceed.
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Getting the Tomcat shutdown port
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Olivier Lefevre [mailto:lefevrol@yahoo.com]
> Subject: Re: Getting the Tomcat shutdown port
> > Your application may be on a shared Tomcat instance someday
> > and System.exit is really bad in that case.
> So let's kill the servlet instead.
The servlet, or the webapp?
> But it's still unclear how you'd do that because from the
> ServletConfig you can get the ServletContext but from the
> ServletContext you can no longer get the Servlet:
There's no "the Servlet"; the ServletContext is for the webapp, which may be comprised of many servlets.
Why don't you simply throw a ServletException in the init() method of the servlets of interest?
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
On 3/1/2011 3:54 PM, Caldarale, Charles R wrote:
> Anything using an org.apache class is Tomcat-specific, and
> therefore not portable.
Oh, right. I had not picked up that LifecycleListener itself is
a Catalina class.
Still, the basic issue is not about the listener per se but how
the app server reacts to an Error thrown during initialization.
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Getting the Tomcat shutdown port
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Olivier Lefevre [mailto:lefevrol@yahoo.com]
> Subject: Re: Getting the Tomcat shutdown port
> Just to be 100% clear, this is a Tomcat thing, not a servlet
> spec thing, right? Just wondering whether it's portable.
Anything using an org.apache class is Tomcat-specific, and therefore not portable.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 01/03/2011 14:46, Olivier Lefevre wrote:
> On 3/1/2011 2:57 PM, Mark Thomas wrote:
>> Providing you throw an Error, Tomcat is guaranteed not to start.
>
> OK! Just to be 100% clear, this is a Tomcat thing, not a servlet
> spec thing, right? Just wondering whether it's portable.
Yes, this is Tomcat specific.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
On 3/1/2011 2:57 PM, Mark Thomas wrote:
> Providing you throw an Error, Tomcat is guaranteed not to start.
OK! Just to be 100% clear, this is a Tomcat thing, not a servlet
spec thing, right? Just wondering whether it's portable.
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 01/03/2011 13:52, Olivier Lefevre wrote:
> On 2/28/2011 8:18 PM, Mark Thomas wrote:
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityListener.java?view=annotate
>>
>
> This is brand new, isn't it? I can't find it in the 7.0.8 sources.
Yes.
> So it may throw a java.lang.Error at Lifecycle.BEFORE_INIT_EVENT
> time but what happens then? I read §10.9 and §11.6 and it only
> talks about the user-configurable exception handling: it does not
> seem to specify what the application server may do internally.
> Besides it is talking about errors that occur much later in the
> life cycle. So, is the whole Tomcat supposed to die if you throw
> at BEFORE_INIT_EVENT?
Providing you throw an Error, Tomcat is guaranteed not to start.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
On 2/28/2011 8:18 PM, Mark Thomas wrote:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityListener.java?view=annotate
This is brand new, isn't it? I can't find it in the 7.0.8 sources.
So it may throw a java.lang.Error at Lifecycle.BEFORE_INIT_EVENT
time but what happens then? I read §10.9 and §11.6 and it only
talks about the user-configurable exception handling: it does not
seem to specify what the application server may do internally.
Besides it is talking about errors that occur much later in the
life cycle. So, is the whole Tomcat supposed to die if you throw
at BEFORE_INIT_EVENT?
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 28/02/2011 19:13, Olivier Lefevre wrote:
> I know it's an interface I have to implement but without some
> concrete class "close" to my problem to look at for guidance
> LifecycleListener in and of itself does not help me much.
Ah, OK. Try this:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityListener.java?view=annotate
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
On 2/28/2011 6:06 PM, Mark Thomas wrote:
> If you want to stop a single Servlet then Servlet.init() is the
> place to it. See section 2.3.2 of the Servlet 3.0 spec.
I.e., the exception throwing approach suggested by C. Caldarale in
the next answer. Yes, it's neat. So I was overcomplicating it.
> org.apache.catalina.LifecycleListener was what I meant
I know it's an interface I have to implement but without some
concrete class "close" to my problem to look at for guidance
LifecycleListener in and of itself does not help me much.
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 28/02/2011 16:59, Olivier Lefevre wrote:
>> Your application may be on a shared Tomcat instance someday
>> and System.exit is really bad in that case.
>
> True. So let's kill the servlet instead.
If you want to stop a single Servlet then Servlet.init() is the place to
it. See section 2.3.2 of the Servlet 3.0 spec.
>> If you really do want to control Tomcat startup, a LifecycleListener
>> is a better approach but Tomcat specific.
>
> There are plenty of LifecycleListener classes in the API; which
> one would work best: ServerLifecycleListener?
org.apache.catalina.LifecycleListener was what I meant
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
> Your application may be on a shared Tomcat instance someday
> and System.exit is really bad in that case.
True. So let's kill the servlet instead. But it's still unclear
how you'd do that because from the ServletConfig you can get the
ServletContext but from the ServletContext you can no longer get
the Servlet: that has been deprecated and that getter now returns
null. But perhaps I am looking in the wrong direction: the
Servlet.destroy APIdoc says "Called by the servlet container to
indicate to a servlet that the servlet is being taken out of service."
which implies that the teardown is initiated elsewhere and that
simply calling destroy wouldn't do anything useful.
> If you really do want to control Tomcat startup, a LifecycleListener
> is a better approach but Tomcat specific.
There are plenty of LifecycleListener classes in the API; which
one would work best: ServerLifecycleListener?
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 28/02/2011 16:12, Olivier Lefevre wrote:
>> Doing this from a servlet begs the question how you are going
>> to restart it.
>
> Not an issue: I want to shut it down at startup if some needed
> resources cannot be found. No pint restarting it then.
Fair enough. I wouldn't do it in a Servlet.init() though. A
ServletContextListener that stops the app starting is probably better.
Your application may be on a shared Tomcat instance someday and
System.exit is really bad in that case.
If you really do want to control Tomcat startup, a LifecycleListener is
a better approach but Tomcat specific.
>> I'm also curious why you want tot do this but System.exit() will
>> have exactly the same result as using the shutdown port.
>
> Does Tomcat set up appropriate shutdown hooks when it starts?
> Otherwise tearing down the VM could cause damage to external
> resources at least.
Yes, which is why I wrote "System.exit() will have exactly the same
result as using the shutdown port.".
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Olivier Lefevre <le...@yahoo.com>.
> Doing this from a servlet begs the question how you are going
> to restart it.
Not an issue: I want to shut it down at startup if some needed
resources cannot be found. No pint restarting it then.
> I'm also curious why you want tot do this but System.exit() will
> have exactly the same result as using the shutdown port.
Does Tomcat set up appropriate shutdown hooks when it starts?
Otherwise tearing down the VM could cause damage to external
resources at least.
-- O.L.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Getting the Tomcat shutdown port
Posted by Mark Thomas <ma...@apache.org>.
On 28/02/2011 15:34, Olivier Lefevre wrote:
> Is there a programmatic way to retrieve it from within
> a webapp, more exactly from within Servlet.init()? I
> can't find one. Same question for the actual command.
>
> As you may have guessed, I want to shut down Tomcat by
> opening a socket and sending it a SHUTDOWN or whatever.
> Maybe there is a less low-level way to do it but I can't
> find it either.
Doing this from a servlet begs the question how you are going to restart
it. I'm also curious why you want tot do this but System.exit() will
have exactly the same result as using the shutdown port.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org