我一直在努力解决这个问题,启动resque和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
我使用的上帝卡皮斯特拉诺食谱是:
# 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
则返回版本。
任何人都知道为什么?
答案 0 :(得分:1)
您是否设置了init.d脚本? 你有神跑吗?
/etc/init.d/god status
您可以尝试手动启动它
/usr/bin/god -c /etc/god/conf.god -D
并检查日志