FEATURE: allow use of redis sentinel via redis_sentinels

Use: DISCOURSE_REDIS_SENTINELS and DISCOURSE_REDIS_HOST to configure redis
sentinel
This commit is contained in:
Sam 2015-06-25 16:51:48 +10:00
parent 18f887772d
commit 8252f4e110
10 changed files with 30 additions and 90 deletions

View File

@ -31,6 +31,25 @@ class GlobalSetting
{"production" => hash} {"production" => hash}
end 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 class BaseProvider
def self.coerce(setting) def self.coerce(setting)

View File

@ -20,12 +20,6 @@ production:
destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile
target: rails target: rails
run_on: all_servers 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 # 5. Copy production.rb file
- source: /config/cloud/cloud66/files/production.rb - source: /config/cloud/cloud66/files/production.rb
destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb
@ -103,12 +97,6 @@ staging:
destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile
target: rails target: rails
run_on: all_servers 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 # 5. Rename production.rb.sample file
- source: /config/cloud/cloud66/files/production.rb - source: /config/cloud/cloud66/files/production.rb
destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb
@ -168,8 +156,6 @@ development:
first_thing: first_thing:
# 1. Permissions on postgres box # 1. Permissions on postgres box
- source: /config/cloud/cloud66/scripts/permissions.sh - source: /config/cloud/cloud66/scripts/permissions.sh
destination: /tmp/scripts/permissions.sh
target: postgresql
apply_during: build_only apply_during: build_only
execute: true execute: true
sudo: true sudo: true
@ -186,12 +172,6 @@ development:
destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile
target: rails target: rails
run_on: all_servers 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 # 5. Move thin config to server
- source: /config/cloud/cloud66/files/thin.yml - source: /config/cloud/cloud66/files/thin.yml
destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml
@ -241,4 +221,4 @@ development:
target: rails target: rails
apply_during: build_only apply_during: build_only
execute: true execute: true
sudo: true sudo: true

View File

@ -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

View File

@ -92,6 +92,10 @@ redis_db = 0
# redis password # redis password
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 Cross-origin Resource Sharing (CORS) directly at the application level
enable_cors = false enable_cors = false
cors_origin = '' cors_origin = ''

View File

@ -29,7 +29,7 @@ MessageBus.on_disconnect do |site_id|
end end
# Point at our redis # 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_enabled = SiteSetting.enable_long_polling
MessageBus.long_polling_interval = SiteSetting.long_polling_interval MessageBus.long_polling_interval = SiteSetting.long_polling_interval

View File

@ -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

View File

@ -354,7 +354,9 @@ module Discourse
end end
def self.sidekiq_redis_config def self.sidekiq_redis_config
{ url: $redis.url, namespace: 'sidekiq' } conf = GlobalSetting.redis_config.dup
conf[:namespace] = 'sidekiq'
conf
end end
def self.static_doc_topic_ids def self.static_doc_topic_ids

View File

@ -6,18 +6,11 @@ class DiscourseRedis
def self.raw_connection(config = nil) def self.raw_connection(config = nil)
config ||= self.config config ||= self.config
redis_opts = {host: config['host'], port: config['port'], db: config['db']} Redis.new(config)
redis_opts[:password] = config['password'] if config['password']
Redis.new(redis_opts)
end end
def self.config def self.config
@config ||= YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env] GlobalSetting.redis_config
end
def self.url(config=nil)
config ||= self.config
"redis://#{(':' + config['password'] + '@') if config['password']}#{config['host']}:#{config['port']}/#{config['db']}"
end end
def initialize(config=nil) def initialize(config=nil)
@ -30,10 +23,6 @@ class DiscourseRedis
@redis @redis
end end
def url
self.class.url(@config)
end
def self.ignore_readonly def self.ignore_readonly
yield yield
rescue Redis::CommandError => ex rescue Redis::CommandError => ex

View File

@ -104,11 +104,6 @@ unless File.exists?("config/database.yml")
`cp config/database.yml.development-sample config/database.yml` `cp config/database.yml.development-sample config/database.yml`
end 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" ENV["RAILS_ENV"] = "profile"

View File

@ -12,14 +12,8 @@ puts "Running: bundle"
system "bundle" system "bundle"
redis_yml = root + '/config/redis.yml'
database_yml = root + '/config/database.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) if !File.exists?(database_yml)
puts "Creating config/database.yml" puts "Creating config/database.yml"
system "cp #{root}/config/database.yml.development-sample #{database_yml}" system "cp #{root}/config/database.yml.development-sample #{database_yml}"