Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I gracefully shut down a Mongrel web server

My RubyOnRails app is set up with the usual pack of mongrels behind Apache configuration. We've noticed that our Mongrel web server memory usage can grow quite large on certain operations and we'd really like to be able to dynamically do a graceful restart of selected Mongrel processes at any time.

However, for reasons I won't go into here it can sometimes be very important that we don't interrupt a Mongrel while it is servicing a request, so I assume a simple process kill isn't the answer.

Ideally, I want to send the Mongrel a signal that says "finish whatever you're doing and then quit before accepting any more connections".

Is there a standard technique or best practice for this?

like image 377
AndrewR Avatar asked Dec 02 '22 08:12

AndrewR


1 Answers

I've done a little more investigation into the Mongrel source and it turns out that Mongrel installs a signal handler to catch an standard process kill (TERM) and do a graceful shutdown, so I don't need a special procedure after all.

You can see this working from the log output you get when killing a Mongrel while it's processing a request. For example:

** TERM signal received.
Thu Aug 28 00:52:35 +0000 2008: Reaping 2 threads for slow workers because of 'shutdown'
Waiting for 2 requests to finish, could take 60 seconds.Thu Aug 28 00:52:41 +0000 2008: Reaping 2 threads for slow workers because of 'shutdown'
Waiting for 2 requests to finish, could take 60 seconds.Thu Aug 28 00:52:43 +0000 2008 (13051) Rendering layoutfalsecontent_typetext/htmlactionindex within layouts/application
like image 127
AndrewR Avatar answered Dec 04 '22 05:12

AndrewR