Raised exceptions are not logged when USR2

Iñaki Baz Castillo ibc at aliax.net
Sat Jan 2 16:27:31 EST 2010


El Sábado, 2 de Enero de 2010, Iñaki Baz Castillo escribió:
> Hi, I use the ready_pipe branch. I set "logger" to log into Syslog, but the
> issue I'll explain here is the same even if I log to a file.
> 
> I runned Unicorn daemonized. Now imagine I do a typo in my Rack config.ru
>  (I use preload=true). When sending USR2 to the master it fails (ok) but
>  the raised exception is not shown in the logger, instead it's lost as
>  $stderr is /dev/null.
> 
> Even worse, imagine Unicorn is not running and I start it daemonized (with
>  a init script). Due to the typo in config.ru I see:
> 
>   "master failed to start, check stderr log for details"
> 
> But the message is useless since stderr is /dev/null so I se nothing in
> Syslog.
> 
> 
> So I suggest the following:
> 
> If the process fails after setting the logger, then rescue any exception,
>  log it to the logger and raise it as normal:
> 
>   rescue => err
>     logger.fatal "#{err.class}:
>  #{err.message}\n#{err.backtrace.join("\n")}" raise err
>   end
> 
> I'm trying to figure where exactly to include such code but it seems a bit
> complex. Any tip please?
> 
> Thanks a lot.

A simpler approach would be removing this line at the end of launcher.rb:

  Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null" 

With this, errors would be displayed in stderr. Of course for workers stderr 
should be reopened to point to /dev/null, but IMHO not for master process.

Perhaps errors preventing the master process to start should be displayed to 
stderr instead of to the logger (as it could be not set yet).

Opinnions?


-- 
Iñaki Baz Castillo <ibc at aliax.net>


More information about the mongrel-unicorn mailing list