Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to silently start Sinatra + Thin?

Tags:

ruby

sinatra

thin

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

like image 774
João Pereira Avatar asked Dec 23 '11 19:12

João Pereira


1 Answers

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/

like image 54
GroovyCakes Avatar answered Nov 04 '22 15:11

GroovyCakes