How to start and stop a Sinatra application using Thin on Windows?
Asked Answered
B

2

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

Benzofuran answered 22/2, 2011 at 7:10 Comment(2)
what do mean by return control? like at the command prompt? Also, the code you have is nowhere near being able to workErickson
Does thin even work on Windows?Sauerbraten
T
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

Tricia answered 31/3, 2011 at 0:22 Comment(2)
How do you stop it after its been deamonize?Immune
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 ...Tricia
O
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

Oaxaca answered 22/2, 2011 at 8:23 Comment(1)
thin start seems to hold control, it does not seem to run in the background.Benzofuran

© 2022 - 2024 — McMap. All rights reserved.