diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index e3cb2532a..323a64a92 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -31,6 +31,25 @@ class GlobalSetting {"production" => hash} end + def self.redis_config + @config ||= + begin + c = {} + c[:host] = redis_host if redis_host + c[:port] = redis_port if redis_port + c[:password] = redis_host if redis_password.present? + c[:db] = redis_db if redis_db != 0 + c[:db] = 1 if Rails.env == "test" + if redis_sentinels.present? + c[:sentinels] = redis_sentinels.split(",").map do |address| + host,port = address.split(":") + {host: host, port: port} + end.to_a + end + c.freeze + end + end + class BaseProvider def self.coerce(setting) diff --git a/config/cloud/cloud66/deploy_hooks.yml b/config/cloud/cloud66/deploy_hooks.yml index dee74d8d6..6d971570b 100644 --- a/config/cloud/cloud66/deploy_hooks.yml +++ b/config/cloud/cloud66/deploy_hooks.yml @@ -20,12 +20,6 @@ production: destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile target: rails run_on: all_servers - # 4. Copy redis settings - - source: /config/cloud/cloud66/files/redis.yml - destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml - target: rails - parse: false - run_on: all_servers # 5. Copy production.rb file - source: /config/cloud/cloud66/files/production.rb destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb @@ -103,12 +97,6 @@ staging: destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile target: rails run_on: all_servers - # 4. Rename redis.yml.sample file - - source: /config/cloud/cloud66/files/redis.yml - destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml - target: rails - parse: false - run_on: all_servers # 5. Rename production.rb.sample file - source: /config/cloud/cloud66/files/production.rb destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb @@ -168,8 +156,6 @@ development: first_thing: # 1. Permissions on postgres box - source: /config/cloud/cloud66/scripts/permissions.sh - destination: /tmp/scripts/permissions.sh - target: postgresql apply_during: build_only execute: true sudo: true @@ -186,12 +172,6 @@ development: destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile target: rails run_on: all_servers - # 4. Rename redis.yml.sample file - - source: /config/cloud/cloud66/files/redis.yml - destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml - target: rails - parse: false - run_on: all_servers # 5. Move thin config to server - source: /config/cloud/cloud66/files/thin.yml destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml @@ -241,4 +221,4 @@ development: target: rails apply_during: build_only execute: true - sudo: true \ No newline at end of file + sudo: true diff --git a/config/cloud/cloud66/files/redis.yml b/config/cloud/cloud66/files/redis.yml deleted file mode 100644 index 25ba0da87..000000000 --- a/config/cloud/cloud66/files/redis.yml +++ /dev/null @@ -1,22 +0,0 @@ -defaults: &defaults - uri: <%= uri = URI.parse( ENV['REDIS_ADDRESS'].nil? ? ENV['REDIS_PROVIDER_URL'] || "redis://localhost:6379" : "redis://#{ENV['REDIS_ADDRESS']}:6379") %> - host: <%= uri.host %> - port: <%= uri.port %> - password: <%= uri.password %> - db: 0 - -development: - <<: *defaults - -profile: - <<: *defaults - -test: - <<: *defaults - db: 1 - -staging: - <<: *defaults - -production: - <<: *defaults diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf index d48960653..faf88116a 100644 --- a/config/discourse_defaults.conf +++ b/config/discourse_defaults.conf @@ -92,6 +92,10 @@ redis_db = 0 # redis password redis_password = +# redis sentinels eg +# redis_sentinels = 10.0.0.1:26381,10.0.0.2:26381 +redis_sentinels = + # enable Cross-origin Resource Sharing (CORS) directly at the application level enable_cors = false cors_origin = '' diff --git a/config/initializers/04-message_bus.rb b/config/initializers/04-message_bus.rb index 7ada7b9ff..308985a6d 100644 --- a/config/initializers/04-message_bus.rb +++ b/config/initializers/04-message_bus.rb @@ -29,7 +29,7 @@ MessageBus.on_disconnect do |site_id| end # Point at our redis -MessageBus.redis_config = YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env].symbolize_keys +MessageBus.redis_config = GlobalSetting.redis_config MessageBus.long_polling_enabled = SiteSetting.enable_long_polling MessageBus.long_polling_interval = SiteSetting.long_polling_interval diff --git a/config/redis.yml b/config/redis.yml deleted file mode 100644 index 5e8b2b5c3..000000000 --- a/config/redis.yml +++ /dev/null @@ -1,21 +0,0 @@ -defaults: &defaults - host: <%= GlobalSetting.redis_host %> - port: <%= GlobalSetting.redis_port %> - password: <%= GlobalSetting.redis_password %> - db: <%= GlobalSetting.redis_db %> - -development: - <<: *defaults - -profile: - <<: *defaults - -test: - <<: *defaults - db: 1 - -staging: - <<: *defaults - -production: - <<: *defaults diff --git a/lib/discourse.rb b/lib/discourse.rb index 5c9737753..bb614b70f 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -354,7 +354,9 @@ module Discourse end def self.sidekiq_redis_config - { url: $redis.url, namespace: 'sidekiq' } + conf = GlobalSetting.redis_config.dup + conf[:namespace] = 'sidekiq' + conf end def self.static_doc_topic_ids diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 8cf03960f..b4943fde9 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -6,18 +6,11 @@ class DiscourseRedis def self.raw_connection(config = nil) config ||= self.config - redis_opts = {host: config['host'], port: config['port'], db: config['db']} - redis_opts[:password] = config['password'] if config['password'] - Redis.new(redis_opts) + Redis.new(config) end def self.config - @config ||= YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env] - end - - def self.url(config=nil) - config ||= self.config - "redis://#{(':' + config['password'] + '@') if config['password']}#{config['host']}:#{config['port']}/#{config['db']}" + GlobalSetting.redis_config end def initialize(config=nil) @@ -30,10 +23,6 @@ class DiscourseRedis @redis end - def url - self.class.url(@config) - end - def self.ignore_readonly yield rescue Redis::CommandError => ex diff --git a/script/bench.rb b/script/bench.rb index fa569991b..ea79eae9a 100644 --- a/script/bench.rb +++ b/script/bench.rb @@ -104,11 +104,6 @@ unless File.exists?("config/database.yml") `cp config/database.yml.development-sample config/database.yml` end -unless File.exists?("config/redis.yml") - puts "Copying redis.yml.sample to redis.yml" - `cp config/redis.yml.sample config/redis.yml` -end - ENV["RAILS_ENV"] = "profile" diff --git a/script/setup_dev b/script/setup_dev index fc71f7f12..ea35daad4 100755 --- a/script/setup_dev +++ b/script/setup_dev @@ -12,14 +12,8 @@ puts "Running: bundle" system "bundle" -redis_yml = root + '/config/redis.yml' database_yml = root + '/config/database.yml' -if !File.exists?(redis_yml) - puts "Creating config/redis.yml" - system "cp #{root}/config/redis.yml.sample #{redis_yml}" -end - if !File.exists?(database_yml) puts "Creating config/database.yml" system "cp #{root}/config/database.yml.development-sample #{database_yml}"