'before_fork' is executed in parallel by two processes ¿?

Eric Wong normalperson at yhbt.net
Tue Jan 5 20:12:26 EST 2010


Iñaki Baz Castillo <ibc at aliax.net> wrote:
> El Miércoles, 6 de Enero de 2010, Eric Wong escribió:
> > Iñaki Baz Castillo <ibc at aliax.net> wrote:
> > > El Martes, 5 de Enero de 2010, Eric Wong escribió:
> > > > Yes, before_fork and after_fork are both called for every worker
> > > > forked.
> > >
> > > So if I just want to test a DB connection then I do better wrtitting such
> > > code out of before_fork in the config file, right? (at least it's the
> > > workaround that works for me).
> > 
> > You can also do it on a certain worker only:
> > 
> >   before_fork do |server, worker|
> >     if worker.nr == 0
> >       ...
> >     end
> >   end
> 
> So if I'm not wrong when before_fork block is runned the $stderr is already 
> redirected to the IO set in "stderr_path", rigth?

Yes, stderr is redirected before any before_fork hooks run.

> Then any error in the config file into before_fork would not vi raised to the 
> terminal screen but to the stderr (if it has been redirected).

If it's a Ruby syntax error, then it would've been sent to the
terminal at startup.  Otherwise it'll be redirected.

> Then I see no advantage on using what you suggest ("if worker.nr == 0 ...") 
> over adding such code at the top of the config file. Do I miss something?

I depends on whether you use preload_app or not, if you use preload_app,
then you'll get to have access to any objects your app creates at
initialization.

-- 
Eric Wong


More information about the mongrel-unicorn mailing list