ruby-on-rails - 在生产中监控 ruby​​ 后台进程(如 Resque)的正确方法

标签 ruby-on-rails centos capistrano god

我已经为此苦苦挣扎了一段时间,启动 resque 和 resque 调度程序等后台进程的正确方法是什么?使用上帝是不是矫枉过正?

目前我正试图让上帝工作,但我不确定 *.god conf 文件是否应该在应用程序的目录或其他地方。

这就是我使用的:

config
 |- app.god
 |- God
   |- resque.god
   |- resque_scheduler.god
# config/god/resque.god
rails_env   = ENV['RAILS_ENV']  || raise(ArgumentError, "RAILS_ENV not defined")
rails_root  = ENV['RAILS_ROOT'] || File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
num_workers = rails_env == 'production' ? 5 : 2

num_workers.times do |num|
  God.watch do |w|
    w.dir      = "#{rails_root}"
    w.name     = "resque-#{num}"
    w.group    = 'resque'
    w.interval = 30.seconds
    w.env      = {"QUEUE"=>"*", "RAILS_ENV"=>rails_env, "BUNDLE_GEMFILE"=>"#{rails_root}/Gemfile"}
    w.start    = "/usr/bin/rake -f #{rails_root}/Rakefile environment resque:work"
    w.log      = "#{rails_root}/log/resque-scheduler.log"

    ... start/stop methods  ...
  end
end

有一个 root 用户和一个 MyApp 用户。 MyApp 用户有一个应用程序位于:/home/myapp/apps/myapp_production/current
我使用的 God capistrano 食谱是:
# config/deploy.rb
after "deploy:restart", "god:restart"

namespace :god do
  def try_killing_resque_workers
    run "pkill -3 -f resque"
  rescue
    nil
  end

  desc "Restart God gracefully"
  task "restart", :roles => :app do
    god_config_path = File.join(release_path, 'config', 'app.god')
    begin
      # Throws an exception if god is not running.
      run "cd #{release_path}; bundle exec god status && RAILS_ENV=#{rails_env} RAILS_ROOT=#{release_path} bundle exec god load #{god_config_path} && bundle exec god start resque"

      # Kill resque processes and have god restart them with the newly loaded config.
      try_killing_resque_workers
    rescue => ex
      # god is dead, workers should be as well, but who knows.
      try_killing_resque_workers

      # Start god.
      run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec god -c #{god_config_path}"
    end
  end
end

当我部署时,我得到 “服务器不可用(或者您没有访问它的权限)”

奇怪的是,我什至以 root 身份登录并运行 god status它什么也不返回,但如果我运行 god --version它返回版本。

有谁知道为什么?

最佳答案

您是否设置了 init.d 脚本?
你有上帝在运行吗?

/etc/init.d/god status

您可以尝试手动启动它
/usr/bin/god -c /etc/god/conf.god -D

并检查日志

关于ruby-on-rails - 在生产中监控 ruby​​ 后台进程(如 Resque)的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490154/

相关文章:

ruby-on-rails - 如何将数据库结构从 db 导出到迁移文件中?

ruby - 在 Centos 5.8 上安装 gitorious(乘客模块)

php - 网站缩略图(截图)

python - 如何使用 cPanel 在 Centos 7 上运行 OpenEDX

ruby-on-rails - Unicorn + Capistrano 零停机部署 -- 不切换到新版本

ruby-on-rails - Rails - 使用 Capistrano 部署后需要重新启动 Nginx?

ruby - Capistrano 3 - 错误 : sorry, 你必须有一个 tty 才能运行 sudo

ruby-on-rails - 在我的 Controller 中,我想接收一些参数,例如 params[ :test][:test_page]

ruby-on-rails - 在 Rails 中进行大量数据迁移

ruby-on-rails - 缩小 Ruby 'where 的标准