2011-09-05 15 views
1

這是我第一次使用神寶石。當我運行命令god terminate它不關閉現有的任務。所以下一次我再次運行神劇本時,它只是雙打。第一次使用神寶石,不關閉魔王

我看到示例腳本Resque有終止流氓產生,但不完全知道如何修改我的腳本。

命令我跑

god -c config/resque.god 
god -c config/stale.god 

我resque.god文件:

RAILS_ROOT = File.dirname(File.dirname(__FILE__)) 

God.watch do |w| 
    w.name   = "android_msg" 
    w.group   = "resque-group" 
    w.interval  = 30.seconds 
    w.start   = "cd #{RAILS_ROOT} && rake resque:work QUEUE='android_message'" 
    w.start_grace = 10.seconds 

    # restart if memory gets too high 
    w.transition(:up, :restart) do |on| 
     on.condition(:memory_usage) do |c| 
     c.above = 350.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 
     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 


God.watch do |w| 
    w.name   = "apn_sender" 
    w.group   = "resque-group" 
    w.interval  = 30.seconds 
    w.start   = "cd #{RAILS_ROOT} && rake apn:sender" 
    w.start_grace = 10.seconds 

    # restart if memory gets too high 
    w.transition(:up, :restart) do |on| 
     on.condition(:memory_usage) do |c| 
     c.above = 350.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 
     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 

stale.god

# This will ride alongside god and kill any rogue stale worker 
# processes. Their sacrifice is for the greater good. 

WORKER_TIMEOUT = 60 * 10 # 10 minutes 

Thread.new do 
    loop do 
    begin 
     `ps -e -o pid,command | grep [r]esque`.split("\n").each do |line| 
     parts = line.split(' ') 
     next if parts[-2] != "at" 
     started = parts[-1].to_i 
     elapsed = Time.now - Time.at(started) 

     if elapsed >= WORKER_TIMEOUT 
      ::Process.kill('USR1', parts[0].to_i) 
     end 
     end 
    rescue 
     # don't die because of stupid exceptions 
     nil 
    end 

    sleep 30 
    end 
end 

回答

0

我認爲你需要做的:

god -c config/resque.god ;; starts god with the given config 
god load config/stale.god ;; loads the given config into an already running god instance 
0

下面的命令並沒有爲我工作:

god load config/stale.god 

周圍挖掘後,我發現,它可能只是在resque.god

require 'stale.god' 
頂部需要