put ldap setting into config file. should load be rails env. Also make god config more friendly.

This commit is contained in:
Matthew K. Fu JuYuan 2012-06-22 14:32:28 +08:00
parent 8dd1ab32c1
commit 86a4a6cbe2
4 changed files with 30 additions and 16 deletions

View File

@ -1 +1,2 @@
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env] APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
LDAP_CONFIG = YAML.load_file("#{Rails.root}/config/ldap.yml")[Rails.env]

View File

@ -6,20 +6,11 @@ $nccu_ldap_connection
module NccuLdapConnection module NccuLdapConnection
BASE = 'ou=People,dc=nccu,dc=edu,dc=tw' BASE = 'ou=People,dc=nccu,dc=edu,dc=tw'
@ldap_host = {
:host => '127.0.0.1', #140.119.166.23 or 127.0.0.1
:port => 8001, #389 or 8001
# :filter => "(uid=#{login_uid})",
# :base => "ou=People,dc=nccu,dc=edu,dc=tw",
:authenticate_info => "cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw",
:authenticate_pwd => "nccu2ucc"
}
def self.establish def self.establish
$nccu_ldap_connection = Net::LDAP.new $nccu_ldap_connection = Net::LDAP.new
$nccu_ldap_connection.port = @ldap_host[:port] $nccu_ldap_connection.port =LDAP_CONFIG["port"]
$nccu_ldap_connection.host = @ldap_host[:host] $nccu_ldap_connection.host = LDAP_CONFIG["host"]
$nccu_ldap_connection.authenticate(@ldap_host[:authenticate_info],@ldap_host[:authenticate_pwd]) $nccu_ldap_connection.authenticate(LDAP_CONFIG["authenticate_info"],LDAP_CONFIG["authenticate_pwd"])
end end
end end

12
config/ldap.yml Normal file
View File

@ -0,0 +1,12 @@
defaults: &defaults
authenticate_info: 'cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw'
authenticate_pwd: 'nccu2ucc'
development:
<<: *defaults
host: '127.0.0.1'
port: 8001
production:
<<: *defaults
host: '140.119.166.23'
port: 389

View File

@ -1,7 +1,14 @@
#developer pls change here
default_uid = 'kaito'
default_gid = 'staff'
rails_env = 'development' #ENV['RAILS_ENV'] || "production" rails_env = 'development' #ENV['RAILS_ENV'] || "production"
rails_root = ENV['RAILS_ROOT'] || "/Users/kaito/Documents/MyWorkspeace/NCCU"
rails_root = ENV['RAILS_ROOT'] || File.expand_path("..",File.dirname(__FILE__))
num_workers = rails_env == 'production' ? 5 : 2 num_workers = rails_env == 'production' ? 5 : 2
num_workers.times do |num| num_workers.times do |num|
God.watch do |w| God.watch do |w|
w.dir = "#{rails_root}" w.dir = "#{rails_root}"
@ -12,8 +19,11 @@ num_workers.times do |num|
# w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} # w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env}
w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}"
w.uid = 'kaito' w.uid = rails_env == 'production' ? nccu : default_uid
w.gid = 'staff' w.gid = rails_env == 'production' ? nccu : default_gid
w.log = "#{rails_root}/log/god.log"
# restart if memory gets too high # restart if memory gets too high
w.transition(:up, :restart) do |on| w.transition(:up, :restart) do |on|