如何在 Windows 上使用 Thin 启动和停止 Sinatra 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5075135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:13:57  来源:igfitidea点击:

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

rubywindowssinatrathin

提问by Prakash Raman

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

我的环境是:Windows,Ruby 1.9.2

回答by scable

Use a config.ru file like Dmitry Maksimov suggested:

使用像 Dmitry Maksimov 建议的 config.ru 文件:

#config.ru
require './your_app_file'

run YourApp

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

然后rackup -D从这意味着 deamonize开始,因此它在后台运行。

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

不过,我不建议将其用于开发。最好看看Shotgun

回答by Dmitry Maksimov

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

在应用程序机架文件的顶级目录中创建 - config.ru - 包含以下内容:

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

require 'your app'
run Sinatra::Application

Then just run your app with the thin start

然后只需运行您的应用程序 thin start