Re: Raised exceptions are not logged when USR2

2010-01-02 Thread Iñaki Baz Castillo
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 i...@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


Re: Raised exceptions are not logged when USR2

2010-01-02 Thread Iñaki Baz Castillo
El Sábado, 2 de Enero de 2010, Iñaki Baz Castillo escribió:
 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).

And the other already available workaround is setting the stderr_path.
Unfortunatelly $stderr.reopen requires a file as parameter so is not possible 
to use Syslog or any other logger, is it?

BTW, how to reset the $stderr so it points again to the default one (the 
terminal)?

-- 
Iñaki Baz Castillo i...@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


unicorn/reexec/bundler/cap deploy issue

2010-01-02 Thread skaar
Hi Eric,

we've run into an issue with Unicorn's reexec, when the rails app is
using Bundler and we deploy into dated release directories. Still not
sure what the correct fix is for this, but what happens is that bundler
modifies (acutally prefixes) PATH/RUBYOPT and when you reexec unicorn
these are passed along to the new master process - and Bundler will
again append to the PATH/RUBYOBT.

This becomes more of a problem when you deploy with capistrano and
include SIGUSR2 restart of your unicorn. And effectively it will attempt
to load all Bundler vendor/bundler_gems/environment.rb for all deploys
since unicorn was first started - and if you have, say, a keep only 5
releases strategy, you will soon get failures when a bundler
environment.rb file in RUBYOPT has been shifted out.

I'm still not sure what the right solution is (to modify unicorn, the
unicorn.rb config file or to address it in bundler), but the following
patch does it brute force in unicorn and introduce the assumption that
a reexec should take the same PATH/RUBYOPT variables as the initial
invokation of the unicorn process (using a similar strategy as with
PWD):


From 3d6ca163723148668d69115ebaf00cb814db8f49 Mon Sep 17 00:00:00 2001
From: skaar sk...@waste.org
Date: Sat, 2 Jan 2010 12:29:38 -0500
Subject: [PATCH] filter PATH/RUBYOPT when rexec, and give new master same 
values as the
 original master process

---
 lib/unicorn.rb |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 225e00a..6b3e334 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -111,6 +111,8 @@ module Unicorn
 Dir.pwd
   end
 }.call,
+  :path = ENV['PATH'],
+  :rybyopt = ENV['RUBYOPT'],
   0 = $0.dup,
 }
 
@@ -488,6 +490,8 @@ module Unicorn
   self.reexec_pid = fork do
 listener_fds = LISTENERS.map { |sock| sock.fileno }
 ENV['UNICORN_FD'] = listener_fds.join(',')
+ENV['PATH'] = START_CTX[:path]
+ENV['RUBYOPT'] = START_CTX[:rubyopt]
 Dir.chdir(START_CTX[:cwd])
 cmd = [ START_CTX[0] ].concat(START_CTX[:argv])
 
-- 
1.6.6.rc3


-- 
/skaar

sk...@waste.org
where in the W.A.S.T.E is the wisdom
s_u_b_s_t_r_u_c_t_i_o_n
___
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