Skip to content

Commit

Permalink
Merge pull request ManageIQ#15326 from bdunne/memcache_server_env_var…
Browse files Browse the repository at this point in the history
…iable

Allow overriding memcache server setting by environment variable
  • Loading branch information
jrafanie authored Jun 20, 2017
2 parents 2f0efbe + f2fd7ff commit 091c64f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/miq_server/environment_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def start_memcached
return unless ::Settings.server.session_store.to_s == 'cache'
return unless MiqEnvironment::Command.supports_memcached?
require "#{Rails.root}/lib/miq_memcached" unless Object.const_defined?(:MiqMemcached)
_svr, port = ::Settings.session.memcache_server.to_s.split(":")
_svr, port = MiqMemcached.server_address.to_s.split(":")
opts = ::Settings.session.memcache_server_opts.to_s
MiqMemcached::Control.restart!(:port => port, :options => opts)
_log.info("Status: #{MiqMemcached::Control.status[1]}")
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if session_store == :mem_cache_store
require 'dalli'
session_options = session_options.merge(
:cache => Dalli::Client.new(Settings.session.memcache_server, :namespace => "MIQ:VMDB", :value_max_bytes => 10.megabytes),
:cache => Dalli::Client.new(MiqMemcached.server_address, :namespace => "MIQ:VMDB", :value_max_bytes => 10.megabytes),
:expire_after => 24.hours,
:key => "_vmdb_session",
)
Expand Down
4 changes: 4 additions & 0 deletions lib/miq_memcached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require 'linux_admin'

module MiqMemcached
def self.server_address
ENV["MEMCACHED_SERVER"] || ::Settings.session.memcache_server
end

class Error < RuntimeError; end
class ControlError < Error; end

Expand Down
3 changes: 1 addition & 2 deletions lib/token_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def self.acquire(namespace, token_ttl)
ActiveSupport::Cache::MemoryStore.new(cache_store_options(namespace, token_ttl))
when "cache"
require 'active_support/cache/dalli_store'
memcache_server = ::Settings.session.memcache_server
ActiveSupport::Cache::DalliStore.new(memcache_server, cache_store_options(namespace, token_ttl))
ActiveSupport::Cache::DalliStore.new(MiqMemcached.server_address, cache_store_options(namespace, token_ttl))
else
raise "unsupported session store type: #{::Settings.server.session_store}"
end
Expand Down

0 comments on commit 091c64f

Please sign in to comment.