Why doesn't SIGTERM quit gracefully?

Eric Wong normalperson at yhbt.net
Thu Apr 25 18:09:51 UTC 2013

Andreas Falk <mail at andreasfalk.se> wrote:
> On Thu, Apr 25, 2013 at 10:51 AM, Eric Wong <normalperson at yhbt.net> wrote:
> > Andreas Falk <mail at andreasfalk.se> wrote:
> >> I'm wondering why SIGINT and SIGTERM both were chosen for the quick
> >> shutdown? I agree with SIGINT but not with SIGTERM. A lot of unix
> >> tools send SIGTERM as default (kill, runit among some) and it seems to
> >> be the standard way of telling a process to quit gracefully but not
> >> among Ruby people (there are a few other ruby processes behaving the
> >> same way). I just think it's weird that the default command will exit
> >> without taking care of their current request.
> >>
> >> Also i'm not on the mailinglist so it would be great if you could cc
> >> mail at andreasfalk.se
> >
> > I think it's weird, too.  But that's what nginx does, and I based most
> > of the UI decisions on nginx (so it's easy to reuse nginx scripts
> > with unicorn).
> Is it something you'd be willing to change?

If nginx developers are willing to change this, definitely.

Otherwise, at this point, I'm not certain what the ramifications of a
change would be to existing users.  Maybe an option would work, but too
many options overwhelms people.

With unicorn, I suppose having the following after_fork hook works:

   # Note: after_fork hook is run before the :QUIT handler is installed,
   # so we can't use the result of trap(:QUIT) at this point:
   after_fork do |server,worker|
     trap(:TERM) { Process.kill(:QUIT, $$) }

If I had to do this all over again[1], graceful shutdown would be the
_only_ option.

[1] - I haven't released a new web server for 2013... yet :)

More information about the mongrel-unicorn mailing list