6

How do I run a Sinatra app as a deamon from the command line?

It is using Thin:

ruby app.rb -p 3000 -e production

I don't like to set it up in the app.rb itself. I want to deamonise it from the command line.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27

2 Answers2

3

From Start Sinatra app in the background with stdout and stderr redirected (append) to a file:

nohup ruby app.rb -p 3000 -e production >> log/log_file 2>&1 &
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27
2

I don't know if it's possible with Ruby. But it's an easy task with rackup.

Just add a config.ru:

require './app'
run Sinatra::Application

And with this in place you can start it as a daemon:

rackup -p 3000 -E production -D
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
  • 1
    *Tried n true™* with a few small sinatra 2.0 apps on my VPS. It works out of the box and let rack handle the webserver: i use (oh God i'm saying it publicly) *webrick* and the method above for any small app i deploy (capistrano). – microspino Mar 08 '19 at 11:40