sidekiq真的god.rb永远不会运行我的工人,来自终端的同一命令呢?

时间:2013-02-26 20:48:45

标签: ruby-on-rails-3 redis sidekiq god

运行god.rb启动并监视Sidekiq这不起作用。在我的上帝配置下面为sidekiq。

从生产终端手动运行sidekiq -C /srv/books/current/config/sidekiq.yml工作正常,但不是sidekiq god.rb配置任何人知道为什么会发生这种情况?日志中没什么。

God.watch do |w|

  w.name = "sidekiq"
  w.interval = 30.seconds
  w.start = "cd #{ENV['RAILS_ROOT']}; sidekiq -C /srv/books/current/config/sidekiq.yml"
  w.stop = "cd #{ENV['RAILS_ROOT']}; exec sidekiqctl stop /srv/books/shared/tmp/pids/sidekiq.pid"
  w.restart = "#{w.stop} && #{w.start}"
  w.start_grace = 10.seconds
  w.restart_grace = 10.seconds
  w.log = File.join(ENV['RAILS_ROOT'], 'log', 'sidekiq.log')

  # determine the state on startup
  w.transition(:init, {true => :up, false => :start}) do |on|
    on.condition(:process_running) do |c|
      c.running = true
    end
  end

  # determine when process has finished starting
  w.transition([:start, :restart], :up) do |on|
    on.condition(:process_running) do |c|
      c.running = true
      c.interval = 5.seconds
    end

    # failsafe
    on.condition(:tries) do |c|
      c.times = 5
      c.transition = :start
      c.interval = 5.seconds
    end
  end

  # start if process is not running
  w.transition(:up, :start) do |on|
    on.condition(:process_running) do |c|
      c.running = false
    end
  end


  # Notifications
  # --------------------------------------
  w.transition(:up, :start) do |on|
    on.condition(:process_exits) do |p|
      p.notify = 'ect'
    end
  end


end

1 个答案:

答案 0 :(得分:1)

您似乎缺少RAILS_ROOT定义。您在脚本中使用它,但它从未定义过。它可能在终端中工作,因为它设置在那里。但是当god.rb运行它时,你不会得到终端环境,而是一个新的终端环境。

尝试将此添加到您的上帝脚本中:

w.env = { 'RAILS_ROOT' => "/srv/books/current",
          'RAILS_ENV' => "production" }

您也可以将其设置为普通的ruby变量,如the example

所示