class DynportTools::Services
Constants
- DEFAULTS
Attributes
redis_config_hash[W]
redis
redis_config_path[W]
redis
redis_path_prefix[W]
redis
solr_data_root[RW]
solr_instance_path[RW]
solr_url[W]
solr
Public Instance Methods
bootstrap_solr()
click to toggle source
# File lib/dynport_tools/services.rb, line 40 def bootstrap_solr raise "#{solr_xml_path} already exists" if solr_bootstrapped? write_solr_xml_when_possible end
create_solr_core(core_name)
click to toggle source
# File lib/dynport_tools/services.rb, line 82 def create_solr_core(core_name) raise "please set solr_instance_path first!" if self.solr_instance_path.nil? raise "please set solr_data_root first!" if self.solr_data_root.nil? post("#{solr_url}admin/cores?action=CREATE&name=#{core_name}&instanceDir=#{solr_instance_path}&dataDir=#{solr_data_root}/#{core_name}") end
get(url)
click to toggle source
# File lib/dynport_tools/services.rb, line 62 def get(url) system_call(%(curl -s "#{url}")) end
head(url)
click to toggle source
# File lib/dynport_tools/services.rb, line 56 def head(url) if code = system_call(%(curl -s -I "#{url}" | head -n 1)).to_s.split(" ").at(1) code.to_i end end
post(url)
click to toggle source
# File lib/dynport_tools/services.rb, line 66 def post(url) system_call(%(curl -s -I -XPOST "#{url}")) end
redis_config()
click to toggle source
# File lib/dynport_tools/services.rb, line 135 def redis_config (redis_config_hash || {}).map { |key, value| "#{key} #{value}" if !value.nil? }.compact.join("\n") end
redis_config_hash()
click to toggle source
# File lib/dynport_tools/services.rb, line 126 def redis_config_hash { :unixsocket => redis_socket_path, :port => 0, :logfile => redis_log_path, :daemonize => "yes" }.merge(@redis_config_hash || {}) end
redis_config_path()
click to toggle source
# File lib/dynport_tools/services.rb, line 118 def redis_config_path "#{redis_path_prefix}.conf" end
redis_log_path()
click to toggle source
# File lib/dynport_tools/services.rb, line 122 def redis_log_path "#{redis_path_prefix}.log" end
redis_path_prefix()
click to toggle source
# File lib/dynport_tools/services.rb, line 110 def redis_path_prefix @redis_path_prefix or raise "redis_path_prefix not set!" end
redis_running?()
click to toggle source
# File lib/dynport_tools/services.rb, line 106 def redis_running? system_call(%(echo "info" | redis-cli -s #{redis_socket_path} 2> /dev/null | grep uptime_in_seconds)).include?("uptime_in_seconds") end
redis_socket_path()
click to toggle source
# File lib/dynport_tools/services.rb, line 114 def redis_socket_path "#{redis_path_prefix}.socket" end
reload_all_solr_cores()
click to toggle source
# File lib/dynport_tools/services.rb, line 92 def reload_all_solr_cores solr_core_names.each do |core_name| reload_solr_core(core_name) end end
reload_solr_core(core_name)
click to toggle source
# File lib/dynport_tools/services.rb, line 98 def reload_solr_core(core_name) post("#{solr_url}admin/cores?action=RELOAD&core=#{core_name}") end
solr_bootstrapped?()
click to toggle source
# File lib/dynport_tools/services.rb, line 30 def solr_bootstrapped? File.exists?(solr_xml_path) end
solr_core_exists?(core_name)
click to toggle source
# File lib/dynport_tools/services.rb, line 78 def solr_core_exists?(core_name) head("#{solr_url}#{core_name}/admin/") == 200 end
solr_core_names()
click to toggle source
# File lib/dynport_tools/services.rb, line 26 def solr_core_names get(solr_url).to_s.scan(/a href=\"(.*?)\/admin/).flatten end
solr_running?()
click to toggle source
# File lib/dynport_tools/services.rb, line 74 def solr_running? head(self.solr_url) == 200 end
solr_url()
click to toggle source
# File lib/dynport_tools/services.rb, line 70 def solr_url @solr_url || DEFAULTS[:solr_url] end
solr_xml_path()
click to toggle source
# File lib/dynport_tools/services.rb, line 22 def solr_xml_path "#{solr_data_root}/solr.xml" end
start_redis()
click to toggle source
# File lib/dynport_tools/services.rb, line 146 def start_redis write_redis_config system_call("redis-server #{redis_config_path}") end
start_solr()
click to toggle source
# File lib/dynport_tools/services.rb, line 34 def start_solr raise "solr already running" if solr_running? raise "solr must be bootstrapped first" if !solr_bootstrapped? exec "solr #{solr_data_root} > #{solr_data_root}/solr.log 2>&1 &" end
system_call(cmd)
click to toggle source
# File lib/dynport_tools/services.rb, line 151 def system_call(cmd) puts "executing: #{cmd}" Kernel.send(:`, cmd) end
unload_solr_core(core_name)
click to toggle source
# File lib/dynport_tools/services.rb, line 88 def unload_solr_core(core_name) post("#{solr_url}admin/cores?action=UNLOAD&core=#{core_name}") end
write_redis_config()
click to toggle source
# File lib/dynport_tools/services.rb, line 139 def write_redis_config raise "please set redis_config_path first!" if redis_config_path.nil? File.open(redis_config_path, "w") do |f| f.puts(redis_config) end end
write_solr_xml()
click to toggle source
# File lib/dynport_tools/services.rb, line 50 def write_solr_xml File.open(solr_xml_path, "w") do |f| f.puts(DEFAULTS[:solr_xml]) end end
write_solr_xml_when_possible()
click to toggle source
# File lib/dynport_tools/services.rb, line 45 def write_solr_xml_when_possible raise "please create #{solr_data_root} first" if !File.directory?(solr_data_root) write_solr_xml end