2012-03-11 7 views
3

신 (godrb.com)을 사용하여 응용 프로그램을 배포 할 때 기존 프로세스의 상태에 관계없이 새로운 프로세스를 시작하는 방법을 작성하려고합니다. 기존 프로세스는 현재 태스크를 완료하는 데 긴 실행 시간 초과가 필요하지만 새 프로세스는 새로 배치 된 코드를 사용하여 즉시 시작되어야합니다.신 - 기존 프로세스가 아직 중지되는 동안 새 프로세스가 시작됩니다.

현재 내가 지금 멈추었을 때 300 초의 시간 제한을 설정했지만 새 프로세스를 시작하기 전에 300 초를 기다립니다. 이 경우

God.watch do |w| 
    w.name = "sidekiq" 
    w.interval = 30.seconds 
    w.start = "bash -lc 'cd /path/to/current && ./bin/sidekiq -P /path/to/shared/pids/sidekiq.pid'" 
    w.stop = "bash -lc 'kill -USR1 `cat /path/to/shared/pids/sidekiq.pid`'" 
    w.stop_timeout = 300.seconds 
    w.pid_file = "/path/to/shared/pids/sidekiq.pid" 
    w.behavior(:clean_pid_file) 
end 

kill -USR1는 현재 작업을 처리 할 때 sidekiq하지만, 일을 더 이상하지에 알려줍니다.

기존 작업자에게는 300 초의 시간 제한을 유지하고 싶지만 kill 명령을 실행하자마자 새 프로세스를 시작하고 싶습니다.

+0

는 유니콘이 어떻게하는지 봤어? 새로운 노동자를 데려오고 새로운 노동자가 오래된 노동자를 죽이게하는 것은 유니콘의 책임입니다. – d11wtq

+0

예,하지만 그 기능은 Unicorn의 일부입니다. 나는 일반적인 프로세스와 비슷한 것을 성취하려고 노력하고있다. – bensie

답변

0

일부 전환을 정의해야한다고 생각합니다.

이 내 god.rb입니다 :

# I'm using Rails 
rails_env = ENV['RAILS_ENV'] || 'development' 
rails_root = '/path/to/current' 
pid_file = "#{rails_root}/tmp/pids/sidekiq.pid" 

God.watch do |w| 
    w.dir = rails_root 
    w.name = "sidekiq" 
    w.interval = 30.seconds 
    w.env = {'RAILS_ENV' => rails_env, 'BUNDLE_GEMFILE' => "#{rails_root}/Gemfile"} 
    w.uid = 'deployer' 
    w.gid = 'staff' 

    w.start = "cd #{rails_root}; bundle exec sidekiq -e #{rails_env} -C#{rails_root}/config/sidekiq.yml -i #{i} -P #{pid_file}&" 
    w.stop = "cd #{rails_root}; bundle exec sidekiqctl stop #{pid_file} 10" 
    w.restart = "#{w.stop} && #{w.start}" 
    w.start_grace = 15.seconds 
    w.restart_grace = 15.seconds 
    w.pid_file = pid_file 
    w.log = "#{rails_root}/log/sidekiq.log" 

    # clean pid files before start if necessary 
    w.behavior(:clean_pid_file) 

    # 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 
    end 

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

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

    # lifecycle 
    w.lifecycle do |on| 
    on.condition(:flapping) do |c| 
     c.to_state = [:start, :restart] 
     c.times = 5 
     c.within = 5.minute 
     c.transition = :unmonitored 
     c.retry_in = 10.minutes 
     c.retry_times = 5 
     c.retry_within = 2.hours 
    end 
    end 
end 
관련 문제