fixing setting template and site init scripts

This commit is contained in:
Matt K. Fu 2013-08-27 17:28:33 +08:00
parent aa8523c8cf
commit d8dd68b4df
4 changed files with 39 additions and 20 deletions

View File

@ -51,17 +51,32 @@ namespace :site do
@resque_namespace = STDIN.gets.gsub("\n",'') @resque_namespace = STDIN.gets.gsub("\n",'')
@resque_namespace = APP_CONFIG['orbit'] if @resque_namespace.empty? @resque_namespace = APP_CONFIG['orbit'] if @resque_namespace.empty?
puts "Is this the only site [ Entry site? ] on this mechine?[Default No]:......"
site_is_alone = false
site_is_alone = STDIN.gets.gsub("\n",'')
site_is_alone = true if site_is_alone.downcase == 'yes'
puts "Is this a primary site?[Default No]:......" puts "Is this a primary site?[Default No]:......"
site_is_primary = false site_is_primary = false
site_is_primary = STDIN.gets.gsub("\n",'') site_is_primary = STDIN.gets.gsub("\n",'')
site_is_primary = true if site_is_primary.downcase == 'yes' site_is_primary = true if site_is_primary.downcase == 'yes'
puts "Is this the only site on this mechine?[Default No]:......" puts "Traffic heavy?[Default No]:......"
site_is_alone = false traffic_heavy = false
site_is_alone = STDIN.gets.gsub("\n",'') traffic_heavy = STDIN.gets.gsub("\n",'')
site_is_alone = true if site_is_alone.downcase == 'yes' traffic_heavy = true if site_is_primary.downcase == 'yes'
@resque_workers = site_is_alone ? 5 : 2 @traffic_rate = traffic_heavy ? 2 : 1
if site_is_alone
@resque_workers = 5 * traffic_rate #Entry Site
else
if site_is_primary
@resque_workers = 2 * traffic_rate #Primary Site
else
@resque_workers = 1 * traffic_rate #Secondary Site
end
end
resque_setting = ERB.new(File.new("lib/template/setting/resque.god.erb").read) resque_setting = ERB.new(File.new("lib/template/setting/resque.god.erb").read)
File.open("config/resque.god", 'w') { |file| file.write(resque_setting.result) } File.open("config/resque.god", 'w') { |file| file.write(resque_setting.result) }

View File

@ -4,7 +4,7 @@ user_home = ENV['HOME'] || File.dirname(__FILE__) + '/../..'
development_uid = '' development_uid = ''
development_gid = '' development_gid = ''
num_workers = rails_env == 'production' ? <%= @resque_workers %> : 2 num_workers = rails_env == 'production' ? <%= @resque_workers %> : 1
num_workers.times do |num| num_workers.times do |num|
God.watch do |w| God.watch do |w|
@ -16,17 +16,16 @@ num_workers.times do |num|
w.interval = 30.seconds w.interval = 30.seconds
queue = case num queue = case num
when 0 when 0..2
'critical'
when 1..2
'high,low' 'high,low'
when 3..num_workers when 3..num_workers
'low' 'low'
end end
w.env = {"QUEUE"=>queue, "RAILS_ENV"=>rails_env} w.pid_file = "#{rails_root}/tmp/#{w.name}.pid"
w.start = "HOME=#{user_home} QUEUE=* RAILS_ENV=#{rails_env} rake -f #{rails_root}/Rakefile resque:work" w.env = {"RAILS_ENV"=>rails_env,"PIDFILE" => w.pid_file ,"HOME"=>user_home, "QUEUE"=>queue, "RAILS_ENV"=>rails_env }
w.start = "rake -f #{rails_root}/Rakefile resque:work"
w.stop = "sudo kill -KILL $(cat #{w.pid_file})"
w.uid = (rails_env == 'production' )? "root" : development_uid w.uid = (rails_env == 'production' )? "root" : development_uid
w.gid = (rails_env == 'production' )? "root" : development_gid w.gid = (rails_env == 'production' )? "root" : development_gid

View File

@ -8,10 +8,12 @@ development_gid = ''
w.dir = rails_root w.dir = rails_root
w.name = "<%= @resque_namespace.nil? ? "" : "#{@resque_namespace}-" %>resque-scheduler" w.name = "<%= @resque_namespace.nil? ? "" : "#{@resque_namespace}-" %>resque-scheduler"
w.group = 'rulingcom' w.group = 'rulingcom'
w.interval = 30.seconds w.interval = 10.seconds
w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} w.pid_file = "#{rails_root}/tmp/#{w.name}.pid"
w.start = "HOME=#{user_home} QUEUE=* RAILS_ENV=#{rails_env} rake -f #{rails_root}/Rakefile resque:scheduler"
w.env = {"QUEUE"=>"*", "RAILS_ENV"=>rails_env,"HOME"=>user_home, "RAILS_ENV"=>rails_env}
w.start = "rake -f #{rails_root}/Rakefile resque:scheduler"
w.stop = "sudo kill -KILL $(cat #{w.pid_file})"
w.uid = (rails_env == 'production' )? "root" : development_uid w.uid = (rails_env == 'production' )? "root" : development_uid
w.gid = (rails_env == 'production' )? "root" : development_gid w.gid = (rails_env == 'production' )? "root" : development_gid

View File

@ -8,13 +8,16 @@ development_gid = ''
w.dir = rails_root w.dir = rails_root
w.name = "<%= @resque_namespace.nil? ? "" : "#{@resque_namespace}-" %>sunspot-solr" w.name = "<%= @resque_namespace.nil? ? "" : "#{@resque_namespace}-" %>sunspot-solr"
w.group = 'rulingcom' w.group = 'rulingcom'
w.interval = 30.seconds w.pid_file = "#{rails_root}/solr/pids/production/sunspot-solr-production.pid"
w.env = {"RAILS_ENV"=>rails_env}
w.start = "HOME=#{user_home} QUEUE=* RAILS_ENV=#{rails_env} rake -f #{rails_root}/Rakefile sunspot:solr:start" w.env = {"RAILS_ENV"=>rails_env,"HOME"=>user_home ,"RAILS_ENV"=>rails_env}
w.start = "rake -f #{rails_root}/Rakefile sunspot:solr:start"
w.stop = "sudo kill -KILL $(cat #{w.pid_file})"
w.keepalive w.keepalive
w.uid = (rails_env == 'production' )? "root" : development_uid w.uid = (rails_env == 'production' )? "root" : development_uid
w.gid = (rails_env == 'production' )? "root" : development_gid w.gid = (rails_env == 'production' )? "root" : development_gid
w.pid_file = "#{rails_root}/solr/pids/production/sunspot-solr-production.pid"
w.log = (rails_env == 'production' )? "/var/log/#{w.group}/#{w.name}.log":"#{rails_root}/log/dev-#{w.name}.log" w.log = (rails_env == 'production' )? "/var/log/#{w.group}/#{w.name}.log":"#{rails_root}/log/dev-#{w.name}.log"
# restart if memory gets too high # restart if memory gets too high