[英]Correct way to monitor ruby background processes (like Resque) in production
我已經為此苦苦掙扎了一段時間,啟動像resque和resque Scheduler這樣的后台進程的正確方法是什么? 使用上帝是一種過度殺傷力嗎?
目前,我正在嘗試讓上帝工作,但是我不確定* .god conf文件是否應該在應用程序的目錄中或其他位置。
這是我用的:
config
|- app.god
|- God
|- resque.god
|- resque_scheduler.god
# config/god/resque.god
rails_env = ENV['RAILS_ENV'] || raise(ArgumentError, "RAILS_ENV not defined")
rails_root = ENV['RAILS_ROOT'] || File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
num_workers = rails_env == 'production' ? 5 : 2
num_workers.times do |num|
God.watch do |w|
w.dir = "#{rails_root}"
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds
w.env = {"QUEUE"=>"*", "RAILS_ENV"=>rails_env, "BUNDLE_GEMFILE"=>"#{rails_root}/Gemfile"}
w.start = "/usr/bin/rake -f #{rails_root}/Rakefile environment resque:work"
w.log = "#{rails_root}/log/resque-scheduler.log"
... start/stop methods ...
end
end
有一個root用戶和一個MyApp用戶。 MyApp用戶的一個應用程序位於: /home/myapp/apps/myapp_production/current
我使用的上帝Capistrano配方是:
# config/deploy.rb
after "deploy:restart", "god:restart"
namespace :god do
def try_killing_resque_workers
run "pkill -3 -f resque"
rescue
nil
end
desc "Restart God gracefully"
task "restart", :roles => :app do
god_config_path = File.join(release_path, 'config', 'app.god')
begin
# Throws an exception if god is not running.
run "cd #{release_path}; bundle exec god status && RAILS_ENV=#{rails_env} RAILS_ROOT=#{release_path} bundle exec god load #{god_config_path} && bundle exec god start resque"
# Kill resque processes and have god restart them with the newly loaded config.
try_killing_resque_workers
rescue => ex
# god is dead, workers should be as well, but who knows.
try_killing_resque_workers
# Start god.
run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec god -c #{god_config_path}"
end
end
end
部署時,出現“服務器不可用(或者您沒有訪問權限)”
奇怪的是,當我什至以root用戶god status
登錄並運行god status
它什么也不返回,但是如果我運行god --version
則它返回版本。
有人知道為什么嗎?
您是否設置了init.d腳本? 你有上帝在奔跑嗎?
/etc/init.d/god status
您可以嘗試手動啟動它
/usr/bin/god -c /etc/god/conf.god -D
並檢查日志
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.