这是我的config.ru:
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
和
logger.info("foooooolanito")
然后我看到了我期待的HOME PAGE文本。
这个项目是从一台拥有Ruby 1.9.3-p327,Passenger 3.0.3,Sinatra 1.3.5的机器上迁移过来的。
我该怎么办?
答案 0 :(得分:0)
在相关位置添加以下行:
require "logger"
logger = Log.new("log/sinatra.log","a+")
logger.sync = true
logger.info("foooooolanito")
基本上您的get '/'
没问题,但您没有在任何地方定义logger
,也没有require
d logger
。
如果您正在考虑别的事情,请告诉我。
答案 1 :(得分:0)
注释掉这一行:
$stdout.reopen(log)
我认为原因是乘客4希望能够通过STDOUT与工人交谈。但是我现在还不确定解决Sinatra日志问题的最佳方法。