unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Why workers die when sending KILL to master?
@ 2010-01-09 21:54 Iñaki Baz Castillo
  2010-01-09 22:41 ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Iñaki Baz Castillo @ 2010-01-09 21:54 UTC (permalink / raw)
  To: mongrel-unicorn

Hi, in my customized "unicorn" executable I create N forks in master process 
to behave as posix_mq readers.

I added a "at_exit" block just in master process so they are killed when the 
master receives a signal to terminate.

The only issue I'm experimenting is the fact that they are not killed if the 
master process receives a KILL signal. However Unicorn workers are terminated 
after master is killed with KILL signal. Could I know how such cool feature is 
implemented?

AFAIK when a process receives a KILL signal it just dies and cannot capture 
such signal so this should be a feature implemented in workers (in some way 
they can detect if master has died, am I right?). If so, could I be pointed to 
the exact code in which the feature is implemented? I would like to replicate 
it in my extra-processes.

Thanks a lot.

-- 
Iñaki Baz Castillo <ibc@aliax.net>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why workers die when sending KILL to master?
  2010-01-09 21:54 Why workers die when sending KILL to master? Iñaki Baz Castillo
@ 2010-01-09 22:41 ` Eric Wong
  2010-01-09 22:58   ` Iñaki Baz Castillo
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2010-01-09 22:41 UTC (permalink / raw)
  To: unicorn list

Iñaki Baz Castillo <ibc@aliax.net> wrote:
> Hi, in my customized "unicorn" executable I create N forks in master process 
> to behave as posix_mq readers.
> 
> I added a "at_exit" block just in master process so they are killed when the 
> master receives a signal to terminate.
> 
> The only issue I'm experimenting is the fact that they are not killed if the 
> master process receives a KILL signal. However Unicorn workers are terminated 
> after master is killed with KILL signal. Could I know how such cool feature is 
> implemented?
> 
> AFAIK when a process receives a KILL signal it just dies and cannot capture 
> such signal so this should be a feature implemented in workers (in some way 
> they can detect if master has died, am I right?). If so, could I be pointed to 
> the exact code in which the feature is implemented? I would like to replicate 
> it in my extra-processes.
> 

Hi Iñaki,

The worker_loop just compares Process.ppid with the original ppid it
was started with.  They wakeup from IO.select() every timeout/2 seconds
to check for original_ppid != ppid if the server is idle.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why workers die when sending KILL to master?
  2010-01-09 22:41 ` Eric Wong
@ 2010-01-09 22:58   ` Iñaki Baz Castillo
  2010-01-09 23:47     ` Iñaki Baz Castillo
  0 siblings, 1 reply; 4+ messages in thread
From: Iñaki Baz Castillo @ 2010-01-09 22:58 UTC (permalink / raw)
  To: mongrel-unicorn

El Sábado, 9 de Enero de 2010, Eric Wong escribió:
> The worker_loop just compares Process.ppid with the original ppid it
> was started with.  They wakeup from IO.select() every timeout/2 seconds
> to check for original_ppid != ppid if the server is idle.

Thanks, I was expecting exactly that as the ppid changes when the master 
process dies :) 


-- 
Iñaki Baz Castillo <ibc@aliax.net>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why workers die when sending KILL to master?
  2010-01-09 22:58   ` Iñaki Baz Castillo
@ 2010-01-09 23:47     ` Iñaki Baz Castillo
  0 siblings, 0 replies; 4+ messages in thread
From: Iñaki Baz Castillo @ 2010-01-09 23:47 UTC (permalink / raw)
  To: mongrel-unicorn

El Sábado, 9 de Enero de 2010, Iñaki Baz Castillo escribió:
> El Sábado, 9 de Enero de 2010, Eric Wong escribió:
> > The worker_loop just compares Process.ppid with the original ppid it
> > was started with.  They wakeup from IO.select() every timeout/2 seconds
> > to check for original_ppid != ppid if the server is idle.
> 
> Thanks, I was expecting exactly that as the ppid changes when the master
> process dies :)

I've implememented the same concept for my extra-processes in a similar way:

        ppid = Process.ppid
        Thread.new do
          loop do
            sleep 4
            if Process.ppid != ppid
              log.fatal "master process did, exiting"
              exit!
            end
          end
        end


-- 
Iñaki Baz Castillo <ibc@aliax.net>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-09 23:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-09 21:54 Why workers die when sending KILL to master? Iñaki Baz Castillo
2010-01-09 22:41 ` Eric Wong
2010-01-09 22:58   ` Iñaki Baz Castillo
2010-01-09 23:47     ` Iñaki Baz Castillo

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).