How to silently start Sinatra + Thin?

拟墨画扇 提交于 2019-12-22 04:55:07

问题


I have a Sinatra::Base webservice which I want to start from a command line Ruby program, so I have this:

# 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

This works as expected but it throws out:

$ 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
...

And I want it to be silent, and let me output what I want. For example, if I start it not daemonized I want to just see some message from the command line program and the log output, something like:

$ 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
...

Also would like to silently shutdown it, hiding:

== Sinatra has ended his set (crowd applauds)

One last question, is this the best option to start a sinatra app with thin from inside an application code(ruby script in this case)?


回答1:


You can turn off Sinatra logging with

set :logging, false

http://www.sinatrarb.com/configuration.html

As far as whether or not this is the best way to start a sinatra app... You might want to look at the "foreman" gem, and the "Procfile" (which Heroku.com uses) as an example:

http://ddollar.github.com/foreman/



来源:https://stackoverflow.com/questions/8619747/how-to-silently-start-sinatra-thin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!