如何让启用 bundler 的 rails 应用程序作为服务与 upstart 一起运行?

Rob*_*ans 1 ruby upstart rails

我可以得到一些随机的 shell 脚本作为服务运行......这不是问题。鉴于我所做的一些 google-ing,我认为这与环境变量有关。所需的 rails 环境变量列表或作为服务运行的示例 rails 应用程序都会有所帮助。

我发现了这个:
https :
//serverfault.com/questions/327965/how-to-start-a-rake-task-using-upstart 这很有帮助,但它包含了 rvm。我喜欢 rvm,但我正在寻找一种方法来做到这一点,而不会增加这种额外的复杂性。虽然我可能被迫这样做...

hed*_*hog 5

假设bundle install --deployment --binstubs确保您创建了一个存根bin/bundle(Bundler 不这样做)。然后在/etc/init/your-app.conf

start on started network-services
stop on stopping network-services

<set env variables you need>

script
pushd <Your app's Gemfile folder>
bin/bundle exec ....
end script
Run Code Online (Sandbox Code Playgroud)

之后,你必须运行

initctl reload-configuration
Run Code Online (Sandbox Code Playgroud)

那应该这样做。