6
class App < Sinatra::Base
  def hello
    "world"
  end
end

From documentation I found that I can start the application like this:

App.run

Although this does not return the control.

How do I start the application in the background and how can I then stop it.

My environment is: Windows, Ruby 1.9.2

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Prakash Raman
  • 13,319
  • 27
  • 82
  • 132

2 Answers2

7

Use a config.ru file like Dmitry Maksimov suggested:

#config.ru
require './your_app_file'

run YourApp

And then start with rackup -D which means deamonize and therefore it runs in the background.

I wouldn't recommend this for development though. Better have a look at Shotgun

scable
  • 4,064
  • 1
  • 27
  • 41
  • 1
    How do you stop it after its been deamonize? – Ian Vaughan Oct 14 '14 at 11:14
  • 1
    http://code.macournoyer.com/thin/usage/ I can't check right now. But a combination of `thin start -C ...` with a config file and deamonizing should give you the possibility to stop it with something like `thin stop -C ...` – scable Oct 14 '14 at 19:42
6

Create in the top directory of your application rackup file - config.ru - with the following content:

# config.ru
$: << File.expand_path(File.dirname(__FILE__))

require 'your app'
run Sinatra::Application

Then just run your app with the thin start

Dmitry Maksimov
  • 2,861
  • 24
  • 19