2013-05-27 77 views
1

這是我config.ru:記錄器與Sinatra 1.4.2,Ruby 2.0.0-p195,Passenger 4.0.3和Rack 1.5.2失敗?

require 'sinatra' 
require 'rack/contrib' 

root_dir = File.dirname(__FILE__) 
require File.join(root_dir,'app.rb') 

set :environment, :development 

log = File.new("log/sinatra.log","a+") 
$stdout.reopen(log) 
$stderr.reopen(log) 
$stderr.sync=true 
$stdout.sync=true 

run Ivende.new 

的app.rb:

require 'sinatra' 
require 'sinatra/reloader' 
require 'time' 
require 'json' 

class Ivende < Sinatra::Application 
enable :sessions 
set :environment, :development 

configure :production do 
set :clean_trace,true 
end 

configure :development do 
set :logging, true 
end 

helpers do 
include Rack::Utils 

end 
require_relative 'models/init' 
require_relative 'helpers/init' 
require_relative 'routes/init' 
end 

內部路由我有這個文件:

class Ivende < Sinatra::Application 

get "/" do 
"HOME PAGE " 
logger.info("foooooolanito") 
end 
end 

奇怪的行爲,我看到的是,當我使用記錄器行調用主路由「/」時,資源管理器向我顯示了典型的乘客錯誤頁面,其中包含以下消息:

An error occurred while starting up the preloader: it did not write a startup response in time. 

在sinatra.log文件獲得:

Ready !> socket: 
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10677 !> 
!> Ready !> socket: 
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10721 !> 
!> Ready !> socket: 
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10774 !> 
!> Ready !> socket: 
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10806 !> 

Apache的日誌裏,我得到:

in 'void 
Passenger::ApplicationPool2::SmartSpawner::throwPreloaderSpawnException(const 
string&, Passenger::SpawnException::ErrorKind, 
Passenger::ApplicationPool2::Spawner::BackgroundIOCapturerPtr&, const 
DebugDirPtr&)' (SmartSpawner.h:150) in 'std::string 
Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' 
(SmartSpawner.h:558) in 'void 
Passenger::ApplicationPool2::SmartSpawner::startPreloader()' 
(SmartSpawner.h:206) in 'virtual 
Passenger::ApplicationPool2::ProcessPtr 
Passenger::ApplicationPool2::SmartSpawner::spawn(const 
Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744) in 'void 
Passenger::ApplicationPool2::Group::spawnThreadRealMain(const 
SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned 
int)' (Implementation.cpp:695) 

[ 2013-05-26 01:36:23.7933 10646/7f6ed6a34700 
agents/HelperAgent/RequestHandler.h:1884 ]: [Client 20] Cannot 
checkout session. An error occurred while starting up the preloader: 
it did not write a startup response in time. [ 2013-05-26 
01:36:24.2287 10646/7f6ed8b49700 Pool2/Spawner.h:739 ]: [App 10874 
stdout] [ 2013-05-26 01:37:54.1869 10646/7f6ed8b49700 
Pool2/Implementation.cpp:762 ]: Could not spawn process for group 
/home/dd/dev/ivende/wsapi#default: An error occurred while starting up 
the preloader: it did not write a startup response in time. in 'void 
Passenger::ApplicationPool2::SmartSpawner::throwPreloaderSpawnException(const 
string&, Passenger::SpawnException::ErrorKind, 
Passenger::ApplicationPool2::Spawner::BackgroundIOCapturerPtr&, const 
DebugDirPtr&)' (SmartSpawner.h:150) in 'std::string 
Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' 
(SmartSpawner.h:558) in 'void 
Passenger::ApplicationPool2::SmartSpawner::startPreloader()' 
(SmartSpawner.h:206) in 'virtual 
Passenger::ApplicationPool2::ProcessPtr 
Passenger::ApplicationPool2::SmartSpawner::spawn(const 
Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744) in 'void 
Passenger::ApplicationPool2::Group::spawnThreadRealMain(const 
SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned 
int)' (Implementation.cpp:695) 

[ 2013-05-26 01:37:54.1871 10646/7f6ed6a34700 
agents/HelperAgent/RequestHandler.h:1884 ]: [Client 20] Cannot 
checkout session. An error occurred while starting up the preloader: 
it did not write a startup response in time. 

如果我從我的config.ru刪除這些行:

log = File.new("log/sinatra.log","a+") 
$stdout.reopen(log) 
$stderr.reopen(log) 
$stderr.sync=true 
$stdout.sync=true 

And:

logger.info("foooooolanito") 

然後我看到我期望的主頁文本。

這個項目是從一臺機器上遷移過來的,它具有Ruby 1.9.3-p327,Passenger 3.0.3,Sinatra 1.3.5,它運行良好。

我該怎麼辦?

回答

0

在相關地方添加這些行:

require "logger" 

logger = Log.new("log/sinatra.log","a+") 
logger.sync = true 

logger.info("foooooolanito") 

基本上你get '/'是好的,但你有沒有在任何地方定義logger也沒有你require d logger

讓我知道你是否在想其他事情。

+0

在升級到ruby 2.0.0之前,這段代碼運行良好,儘管如此,我試過了您的建議,並顯示了典型的乘客錯誤頁面,抱怨'Log'未定義,但缺少一些寶石? – ddsangar

+0

追加時不需要'a +',只有'a'是。如果只需要寫訪問權限,'a +'意味着「如果文件存在並且移動到最後,則創建它,並且允許對文件進行讀/寫訪問」。 –

0

註釋掉該行:

$stdout.reopen(log) 

我認爲原因是乘客4只希望能夠在標準輸出交談的工人。然而,我不確定現在解決Sinatra日誌記錄問題的最佳方法。