2012-08-23 44 views
2

我有一个问题,从上帝运行resque工人。不承认已启动resque工人

这里是我的上帝配置

num_workers = 9 
queue  = '*' 
current_path = "/u/apps/narg/current" 

God.pid_file_directory = "/u/apps/narg/current/tmp/pids" 
num_workers.times do |num| 
    God.watch do |w| 
    w.name  = "resque-#{num}" 
    w.group = "resque_all" 
    w.interval = 30.seconds 
    w.env  = {"QUEUE"=>queue, "RAILS_ENV"=>"production", 
      'PIDFILE' => "#{current_path}/tmp/pids/#{w.name}.pid" } 
w.start = "cd #{current_path} ; bundle exec rake environment resque:work" 
w.log  = "#{current_path}/log/god-#{w.name}.log" 
w.pid_file = "#{current_path}/tmp/pids/#{w.name}.pid" 
w.uid = 'root' 
w.gid = 'root' 
w.behavior(:clean_pid_file) 
# retart if memory gets too high 
w.transition(:up, :restart) do |on| 
    on.condition(:memory_usage) do |c| 
    c.above = 150.megabytes 
    c.times = 2 
    end 
end 

# determine the state on startup 
w.transition(:init, { true => :up, false => :start }) do |on| 
    on.condition(:process_running) do |c| 
    c.running = true 
    c.interval = 5 
    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 
    end 
end 

当我开始神,而工人在工作,一切都看起来不错,和它运行的所有转变为:最高。

但是,当工人没有运行时,它会在启动后停止。工人实际上是开始的,pid文件也是正确的。只有上帝没有得到它:

** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 move 'unmonitored' to 'init' 
** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 moved 'unmonitored' to 'init' 
** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 [trigger] process is not running (ProcessRunning) 
** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 move 'init' to 'start' 
** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 before_start: deleted pid 
** [out :: narg-wrk02] I [2012-08-23 11:40:48] INFO: resque-7 start: cd /u/apps/narg/current ; bundle exec rake environment resque:work 

如前所述,工人开始运行良好。此外,该pid文件包含正确的PID。

如果我现在杀神,并重新启动它,它识别运行工精细,并转换为:最高..

任何意见或指针?

回答

0

尝试改变

w.start = "cd #{current_path} ; bundle exec rake environment resque:work"

w.start = "cd #{current_path} ; bundle exec rake environment resque:work &"

这解决了同样的问题对我来说。

0

我定了同样的问题有:

w.start = "cd #{current_path} && rake environment RAILS_ENV=production resque:work &"