0
我一直在为此苦苦挣扎了一段时间,启动后台进程(如resque和resque scheduler)的正确方法是什么?用神是一种矫枉过正?在生产中监控ruby后台进程(如Resque)的正确方法
目前我试图让上帝工作,但我不确定* .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 --version
它返回的版本。
任何人都知道为什么?
我相信“神--version”只是要求神二进制呼应出来的版本,而“神的地位“实际上试图与正在运行的上帝过程交谈。上帝以用户身份运行(除非另有说明,否则它会产生的任何内容都将以该用户身份启动)。我不确定它是否仅仅是我们的旧版本,但是“神状态”似乎启动了一个神守护进程,因为无论你是谁,只要它还没有运行。在我们的例子中,我们想要的真正的上帝守护程序以普通用户的身份运行,任何使用root来检查它的人都会以root身份启动守护程序(这是我们不想要的)。 – 2017-01-09 15:12:16