How to silently start Sinatra + Thin?
Asked Answered
C

1

7

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)?

Cultus answered 23/12, 2011 at 19:4 Comment(0)
M
2

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/

Mutual answered 24/1, 2012 at 13:54 Comment(3)
If using SinatraBase, you have to do it inside the class declaration... sinatrarb.com/…Mutual
You could also try the enable/disable-style setting of optionsMutual
You can see github.com/sinatra/sinatra/blob/… that it's not possible to silence the shutdown (or startup) messages (unless you reopen stderr, but seems inadvisable).Algorism

© 2022 - 2024 — McMap. All rights reserved.