24

私は、2 つのストーカー プロセスを監視することになっている神のスクリプトを持っています。問題は、24 時間後に開始されるプロセスが多すぎることです。

これは神のスクリプトです。

rails_root = File.expand_path("../..", __FILE__)

2.times do |n|
  God.watch do |w|
    w.group = "app-scripts"
    w.name  = "run-#{n}"
    w.interval = 30.seconds
    w.dir      = File.dirname(__FILE__)

    w.env = {
      "BUNDLE_GEMFILE" => "#{rails_root}/Gemfile",
      "RAILS_ENV" => "production",
      "BEANSTALK_URL" => "beanstalk://127.0.0.1:54132"
    }

    w.start = "bbundle exec stalk #{File.join(rails_root, "config/jobs.rb")}"

    w.start_grace = 5.seconds
    w.stop_grace  = 5.seconds

    w.start_if do |start|
      start.condition(:process_running) { |c| c.running = false }
    end

    w.restart_if do |restart|
      restart.condition(:memory_usage) do |c|
        c.above = 200.megabytes
        c.times = [3, 5]
      end

      restart.condition(:cpu_usage) do |c|
        c.above = 95.percent
        c.times = 5
      end
    end

    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
end

ps aux | grep stalk以下を返します。

root      3178  0.2  2.7 417580 117284 ?       Sl   Oct28   2:22 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root      3179  0.2  3.3 506068 138740 ?       Sl   Oct28   2:26 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root      4588  0.2  2.9 497932 121664 ?       Sl   Oct25  16:10 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root      4794  0.2  3.0 497792 128084 ?       Sl   Oct25  15:57 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     10391  0.2  2.8 496784 121388 ?       Sl   Oct25  15:44 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     10392  0.2  2.8 497624 121528 ?       Sl   Oct25  15:31 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     18874 75.0  2.0 214116 83948 ?        Rl   15:49   0:09 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     18875 75.0  2.0 214944 84868 ?        Rl   15:49   0:09 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     20649  0.2  2.6 410636 110012 ?       Sl   Oct28   2:44 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     20650  0.2  3.0 439284 128996 ?       Sl   Oct28   2:47 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     23272  0.2  2.7 414452 115772 ?       Sl   Oct28   2:44 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     23273  0.2  2.7 417728 117152 ?       Sl   Oct28   2:44 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     25919  0.2  3.1 436276 131876 ?       Sl   Oct28   2:28 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     25920  0.2  3.3 503236 138676 ?       Sl   Oct28   2:29 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     28782  0.2  2.8 431836 121108 ?       Sl   Oct25  16:58 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     30687  0.2  2.7 415908 117008 ?       Sl   Oct28   2:39 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb
root     30688  0.2  2.6 476184 111844 ?       Sl   Oct28   2:37 ruby /opt/www/myapp/shared/bundle/ruby/1.9.1/bin/stalk /opt/www/myapp/current/config/jobs.rb

これが/usr/bin/bbundleスクリプトです。

#!/usr/bin/env bash

if [[ -s "/home/webmaster/.rvm/environments/ruby-1.9.2-p320@webmaster" ]]
then
  source "/home/webmaster/.rvm/environments/ruby-1.9.2-p320@webmaster"
  bundle  "$@"
else
  echo "ERROR: Missing RVM environment file: '/home/webmaster/.rvm/environments/ruby-1.9.2-p320@webmaster'" >&2
  exit 1
fi
  • 実行sudo god stop app-scriptsしてもプロセスは強制終了されません。

  • w.uid = "webmaster"神スクリプトに追加しようとしましたが、問題は残ります。

  • 神版0.12.1、ルビー版1.9.3p286、ストーカー版を運用してい0.9.0ます。

私は何を間違っていますか?

4

4 に答える 4

5

フォローしようとしているようgodで、フォローしようとしてbbundleいないようstalkです。godフォローしたい実際のプロセスのPIDがどこにあるかを知らせる必要がありますw.pid_filekill標準でうまくいかない場合は、プロセスを強制終了する方法も説明する必要があります。そのためw.stop_signalには、別の信号(simonmenkeが提案したように)またはw.stop他のコマンド全体に使用できます。

ログファイルは、何が起こっているのかをより明らかにするはずです。またはgod -Dに印刷するために呼び出します。stdoutgod -l /var/log/god.log

于 2012-11-02T18:05:29.670 に答える
2

スタッカーは、INTシグナル (シグナルではないTERM) を受信すると停止します。停止信号を追加してみてください:

# ...
w.stop_signal = 'INT'
# ...
于 2012-11-02T11:58:40.280 に答える
1

これはあなたの質問に役立つはずです: Monitor a Rake task with God .

つまり、神の構成に PID ファイルへの参照を保存できます。

 God.watch do |w|
   w.dir = "#{rails_root}"
   w.name = "my_task"
   w.interval = 10.seconds
   w.pid_file = "#{rails_root}/tmp/pids/#{w.name}.pid"
   w.env = {"RAILS_ENV"=>rails_env, 'PIDFILE' => w.pid_file}
   w.start = "bundle exec rake my_task &"
   ...
 end

実行中のプロセスで、このファイルに PID (この例では rake) を書き込みます。

 task :my_task => :environment do
   File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid } if ENV['PIDFILE']
   Model.perform_task!
 end

God が監視している PID ファイルのパスを、実際に監視されていて、その PID をそのファイルに書き込むプロセス (God が監視するプロセス) に渡します。お役に立てれば。

于 2012-11-06T20:41:04.863 に答える