我有一个使用 Thin 运行的模块化 Sinatra Web 应用程序,EventMachine 运行其他任务。
它可以工作,但网络服务器有点奇怪:任何请求,无论是成功的还是 404 的,都不会出现在 Thin/Sinatra 的日志输出中。当我取消该过程时,服务器会结束两次。
这是应用程序的粗略基本结构:
档案:
web: ruby app.rb
应用程序.rb:
require 'thin'
require 'eventmachine'
require 'app/frontend'
EM.run do
# Start some background tasks here...
EM.add_periodic_timer(1200) do
# Do a repeating task here...
end
App::Frontend.run!
end
应用程序/前端.rb:
require 'sinatra/base'
module App
class Frontend < Sinatra::Base
get '/' do
# Display page
end
# etc
end
end
当我这样做时foreman start
,我得到:
16:50:00 web.1 | started with pid 76423
16:50:01 web.1 | [messages about EventMachine background tasks starting]
16:50:01 web.1 | == Sinatra/1.4.3 has taken the stage on 5000 for development with backup from Thin
16:50:01 web.1 | >> Thin web server (v1.5.1 codename Straight Razor)
16:50:01 web.1 | >> Maximum connections set to 1024
16:50:01 web.1 | >> Listening on 0.0.0.0:5000, CTRL+C to stop
当我请求现有网页(加载正常)或不存在的网页时,没有更多输出。当我取消该过程时,我得到:
^CSIGINT received
16:50:08 system | sending SIGTERM to all processes
SIGTERM received
16:50:08 web.1 | >> Stopping ...
16:50:08 web.1 | == Sinatra has ended his set (crowd applauds)
16:50:08 web.1 | >> Stopping ...
16:50:08 web.1 | == Sinatra has ended his set (crowd applauds)
16:50:08 web.1 | exited with code 0
Sinatra 完成了两次让我觉得我以某种方式运行了两次,而服务于网页的那个没有被记录......但我不知道我是如何管理这个的!