Unicorn启动时运行命令

时间:2015-07-20 04:57:46

标签: ruby-on-rails delayed-job unicorn

我目前正在使用Ubuntu上带有Unicorn的Rails服务器的Digital Ocean实例。除了一件事,我已经把一切都搞定了。

有一个gem我使用被叫延迟作业,它需要作为守护进程启动,以便在服务器重新启动时正常运行。问题是,宝石似乎已经非常许多不同的启动方式,其中许多方式都不受我当前版本的支持。所以,我想的不是搜索成堆的不适用的文档,而是用我认识的shell命令启动它。

我没有使用像Capistrano这样的东西 - 那么在Unicorn启动时运行命令行脚本的最佳方式是什么?我必须跑

cd /home/rails/ 
RAILS_ENV=production bin/delayed_job start

感谢。

1 个答案:

答案 0 :(得分:0)

使用Foreman gem。

通过执行foreman start,您可以轻松地一次性启动应用程序。您将需要一个名为Procfile的配置文件。

这是我Procfile的一个示例。在这里,我用它来运行Unicorn,MailCatcher和Sidekiq。

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
mailcatcher: ruby -rbundler/setup -e "Bundler.clean_exec('mailcatcher --foreground --ip=0.0.0.0')"
worker: bundle exec sidekiq -C ./config/sidekiq.yml

在你的情况下,它会是这样的:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work

参考:https://devcenter.heroku.com/articles/delayed-job

相关问题