Forum: JRuby Gracefully shutting down JRuby app on Tomcat

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B092c2305804b24229d52b8d8e948a11?d=identicon&s=25 Jose R. (increaser)
on 2015-04-01 21:02
Currently I have a large JRuby application running on Tomcat. I have
generic scripts for managing my tomcat applications. However, my JRuby
app shuts down before all the currently running requests are done. So
I'm trying to get my app to wait them to finish before terminating.

My thoughts so far:
1) Trap the "TERM" signal with "Signal.trap"
2) Respond to load balancer to give the server no more traffic
3) ??? Wait for remaining request threads to finish responding
4) Normal cleanup in "at_exit"

The problem I have is with #3. I'm having difficulty trying to figure
out if there are any web requests still processing. I can see here
(http://wiki.apache.org/tomcat/FAQ/Monitoring) that there are some
useful JMX beans I could use but I don't know how to import the classes
(How does "Catalina: type=ThreadPool,name="[depends]"" translate to a
java_import?). Hell, even after figuring out how to get in the bean I'm
going to have to play around to see if I can get the information I need
(Get the active thread count, but does it include everything not just
request threads? Am I going to have to iterate and check the information
for each thread? etc.).

Any suggestions? Perhaps I'm going about this the completely wrong way.

Version info: Java 6; JRuby 1.67; Ruby 1.8.7

Thanks!
Jose
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2015-04-02 08:03
(Received via mailing list)
Why does your app shut down in the first place? Do you have a logger or
a
backtrace in place?
B092c2305804b24229d52b8d8e948a11?d=identicon&s=25 Jose R. (increaser)
on 2015-04-02 19:18
Many reasons. :) One reason is maintenance on the server. Yep I have a
logger and a backtrace.
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2015-04-07 08:53
(Received via mailing list)
(sorry for the late reply: long Easter weekend)

I usually do not trust the container to stop properly a jruby/war
applet.
Catching a TERM signal is not very clean to me.

Instead I usually have a special route, with either a DELETE or HEAD
verb,
coupled with encrypted token in the header, allowing me through a curl
request to properly stop the webapp.

I had to do this as too many times the webapp closed without releasing
the
persisted database files (I'm on Windows using embedded databases). You
might want to explore this path.

Good luck!
This topic is locked and can not be replied to.