From 3baf3e68c1a7f4d1187e292cc5001fb1dc379194 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 23 Apr 2009 23:27:02 -0700 Subject: Allow std{err,out}_path to be changed via HUP Seems like a good idea to be able to relocate log files on a config reload. --- lib/unicorn.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 6d0eccb..9510e4b 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -101,9 +101,6 @@ module Unicorn raise ArgumentError, "no listeners" if LISTENERS.empty? self.pid = @config[:pid] build_app! if @preload_app - File.open(@stderr_path, "a") { |fp| $stderr.reopen(fp) } if @stderr_path - File.open(@stdout_path, "a") { |fp| $stdout.reopen(fp) } if @stdout_path - $stderr.sync = $stdout.sync = true spawn_missing_workers self end @@ -139,6 +136,9 @@ module Unicorn (set_names - cur_names).each { |addr| listen(addr) } end + def stdout_path=(path); redirect_io($stdout, path); end + def stderr_path=(path); redirect_io($stderr, path); end + # sets the path for the PID file of the master process def pid=(path) if path @@ -598,5 +598,10 @@ module Unicorn START_CTX[:argv]).join(' ') end + def redirect_io(io, path) + File.open(path, 'a') { |fp| io.reopen(fp) } if path + io.sync = true + end + end end -- cgit v1.2.3-24-ge0c7