【发布时间】:2012-01-27 00:45:18
【问题描述】:
我有一个 Sinatra::Base 网络服务,我想从命令行 Ruby 程序启动它,所以我有这个:
# command line program file
require 'mymodule/server'
puts "Running on 0.0.0.0:4567, debugging to STDOUT..."
MyModule::Server.run! bind: '0.0.0.0', port: 4567, environment: :production
这按预期工作,但它抛出了:
$ myscript
Running on 0.0.0.0:4567, debugging to STDOUT...
== Sinatra/1.3.1 has taken the stage on 4567 for production with backup from Thin
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop
127.0.0.1 - - [23/Dec/2011 18:44:55] "POST /images HTTP/1.1" 200 360 0.0133
...
我希望它保持沉默,让我输出我想要的东西。例如,如果我启动它而不是守护进程,我只想从命令行程序和日志输出中看到一些消息,例如:
$ myscript
Running on 0.0.0.0:4567, debugging to STDOUT...
127.0.0.1 - - [23/Dec/2011 18:44:55] "POST /images HTTP/1.1" 200 360 0.0133
...
也想静默关机,隐藏:
== Sinatra has ended his set (crowd applauds)
最后一个问题,这是从应用程序代码(在本例中为 ruby 脚本)中启动 sinatra 应用程序的最佳选择吗?
【问题讨论】: