【问题标题】:Run a command whenever Unicorn starts每当 Unicorn 启动时运行命令
【发布时间】:2015-10-09 03:19:17
【问题描述】:

我目前正在使用带有 Unicorn 的 Rails 服务器在 Ubuntu 上开发 Digital Ocean 实例。除了一件事,我已经让一切都运行起来了。

我正在使用一个名为延迟作业的 gem,它需要作为守护程序启动才能在服务器重新启动时正常运行。问题是 gem 似乎有许多不同的启动方式非常,我当前的版本不支持其中的许多方式。因此,我认为与其搜索成堆的不适用文档,不如使用我知道有效的 shell 命令启动它。

我没有使用 Capistrano 之类的东西 - 那么在 Unicorn 启动时运行命令行脚本的最佳方式是什么?我得跑了

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

谢谢。

【问题讨论】:

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


    【解决方案1】:

    使用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

    【讨论】:

    • 这不需要手动启动服务器吗?我已经让独角兽自动启动了。
    猜你喜欢
    • 1970-01-01
    • 2018-12-31
    • 2020-12-31
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 2017-05-29
    相关资源
    最近更新 更多