From 079b9145c34d384dc4da463588b91bf7a30488de Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 24 Jun 2013 16:29:30 +0800 Subject: [PATCH] move all *.god to *.erb so the God init won't go wrong --- lib/tasks/site.rake | 27 ++++++++++++++++++- .../template/setting/resque.god.erb | 2 +- .../template/setting}/resque_schedule.god | 2 +- .../template/setting/solr.god.erb | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) rename config/resque.god => lib/template/setting/resque.god.erb (95%) rename {config => lib/template/setting}/resque_schedule.god (95%) rename config/solr.god => lib/template/setting/solr.god.erb (95%) diff --git a/lib/tasks/site.rake b/lib/tasks/site.rake index 42aa52014..2bf17207a 100644 --- a/lib/tasks/site.rake +++ b/lib/tasks/site.rake @@ -1,4 +1,5 @@ # encoding: utf-8 +require 'erb' namespace :site do @@ -9,16 +10,38 @@ namespace :site do Site.create( :school => 'RulingDigital University', :department => 'Computer Science', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ]) User.create!(:email=>'chris@rulingcom.com',:admin=>true,:user_id=>'chris',:password=>'password') `mongo #{Mongoid.config.database.name} --eval "db.fs.chunks.ensureIndex({files_id: 1, n: 1})"` + puts "Congres you can now login within url" puts 'Please upload design package (/admin/designs/upload_package ) and run rake site:necessary_data' I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :zh_tw => '英文' ) I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' ) - Info.create!(key: "profile", built_in: true, disabled: false, title: {"zh_tw"=>"基本欄位", "en"=>"Basic Info"}, to_search: false) + Info.create!(key: "profile", built_in: true, disabled: false, title: {"zh_tw"=>"基本欄位", "en"=>"Basic Info"}, to_search: false) end task :necessary_data => :environment do + puts "Enter your resque namespace[Orbit]:......" + resque_namespace = gets.chomp + resque_namespace = APP_CONFIG['orbit'] if resque_namespace.empty? + + puts "Is this a primary site?[Default No]:......" + site_is_primary = False + site_is_primary = gets.chomp + site_is_primary = True if site_is_primary.downcase == 'yes' + + resque_setting = ERB.new(File.new("#{$script_root}/lib/template/setting/resque.god.erb").read) + File.open("#{nginx_root}/config/resque.god", 'w') { |file| file.write(resque_setting.result) } + + resque_schedule_setting = ERB.new(File.new("#{$script_root}/lib/template/setting/resque_schedule.god.erb").read) + File.open("#{nginx_root}/config/resque_schedule.god", 'w') { |file| file.write(resque_schedule_setting.result) } + + if site_is_primary + solr_setting = ERB.new(File.new("#{$script_root}/lib/template/setting/solr.god.erb").read) + File.open("#{nginx_root}/config/solr.god", 'w') { |file| file.write(solr_setting.result) } + end + site = Site.first site.title = 'RulingOrbit Demo Site' + site.resque_namespace = resque_namespace site.save # home_trans = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁') @@ -31,6 +54,8 @@ namespace :site do home.title_translations = {"zh_tw"=>"首頁", "en"=>"Home"} home.save + + puts "Rember to restart server after you setup all sites for starting God" end end diff --git a/config/resque.god b/lib/template/setting/resque.god.erb similarity index 95% rename from config/resque.god rename to lib/template/setting/resque.god.erb index 4985aba46..ec8da83f3 100644 --- a/config/resque.god +++ b/lib/template/setting/resque.god.erb @@ -10,7 +10,7 @@ num_workers.times do |num| God.watch do |w| w.dir = rails_root - w.name = "resque-worker-#{num}" + w.name = "<%= namespace.nil? ? "" : "#{namespace}-" %>resque-worker-#{num}" w.group = 'rulingcom' w.interval = 30.seconds diff --git a/config/resque_schedule.god b/lib/template/setting/resque_schedule.god similarity index 95% rename from config/resque_schedule.god rename to lib/template/setting/resque_schedule.god index 0c0fef7e5..301e1b812 100644 --- a/config/resque_schedule.god +++ b/lib/template/setting/resque_schedule.god @@ -6,7 +6,7 @@ development_gid = '' God.watch do |w| w.dir = rails_root - w.name = "resque-scheduler" + w.name = "<%= namespace.nil? ? "" : "#{namespace}-" %>resque-scheduler" w.group = 'rulingcom' w.interval = 30.seconds w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} diff --git a/config/solr.god b/lib/template/setting/solr.god.erb similarity index 95% rename from config/solr.god rename to lib/template/setting/solr.god.erb index 10bb2e33f..6b4e6770b 100644 --- a/config/solr.god +++ b/lib/template/setting/solr.god.erb @@ -6,7 +6,7 @@ development_gid = '' God.watch do |w| w.dir = rails_root - w.name = "sunspot-solr" + w.name = "<%= namespace.nil? ? "" : "#{namespace}-" %>sunspot-solr" w.group = 'rulingcom' w.interval = 30.seconds w.env = {"RAILS_ENV"=>rails_env}