OpenShift::Runtime::Frontend::Http::Plugins::ApacheDBJSON
SNI Proxy Database
Structure: fqdn => {
aliases => [ alias1, alias2, alias3, ... ] connections => { port1 => backend 1 port2 => backend 2 port3 => backend 3 }
}
# File lib/openshift/runtime/frontend/http/plugins/haproxy-sni-proxy.rb, line 203 def callout begin cfg_template = ERB.new(File.read(@filename + "-cfg.erb")) listen_template = ERB.new(File.read(@filename + "-listen.erb")) sni_template = ERB.new(File.read(@filename + "-sni.erb")) server_template = ERB.new(File.read(@filename + "-server.erb")) proxy_cfg = ::OpenShift::Config.new(CONFIG_PATH) # Go through contortions to bind to just the external IP address. # This can be obtained in the following ways: # 1. The BIND_IP setting in our own module configuration. # 2. Reading the first IP address off of EXTERNAL_ETH_DEV # 3. The route that points to PUBLIC_IP (on some clouds, PUBLIC_IP isn't local). # 4. If all of those fail, bind to any addr bind_ip = (proxy_cfg.get("BIND_IP") or "") if bind_ip == "" config = ::OpenShift::Config.new test_iface = config.get("EXTERNAL_ETH_DEV") test_public = config.get("PUBLIC_IP") if test_iface out, err, rc = ::OpenShift::Runtime::Utils::oo_spawn("ip -o -4 addr show dev #{test_iface}") if out=~/inet (\d+\.\d+\.\d+\.\d+)/ bind_ip=$1 end elsif test_public out, err, rc = ::OpenShift::Runtime::Utils::oo_spawn("ip -o -4 route get #{test_public}") if out=~/src (\d+\.\d+\.\d+\.\d+)/ bind_ip=$1 end end end ports = (proxy_cfg.get("PROXY_PORTS") or DEFAULT_SNI_PROXY_PORTS).split(",").map { |p| p.to_i } haproxy_user = (proxy_cfg.get("HAPROXY_USER") or "haproxy") haproxy_run_path = (proxy_cfg.get("HAPROXY_RUN_PATH") or "/var/lib/haproxy") File.open(@filename + ".cfg" + "-", File::RDWR | File::CREAT | File::TRUNC, 0640) do |f| f.write(cfg_template.result(binding)) ports.each do |port| bind_addrs=[] if (bind_ip != "") and (bind_ip!="127.0.0.1") bind_addrs << "127.0.0.1:#{port}" end bind_addrs << "#{bind_ip}:#{port}" f.write(listen_template.result(binding)) self.each do |fqdn, entry| entry["connections"].select { |p, b| p.to_i == port }.each do |p, backend| sni_name = fqdn f.write(sni_template.result(binding)) entry["aliases"].each do |sni_name| f.write(sni_template.result(binding)) end f.write(server_template.result(binding)) end end end f.fsync end oldstat = File.stat(@filename + ".cfg") File.chown(oldstat.uid, oldstat.gid, @filename + ".cfg" + "-") File.chmod(oldstat.mode & 0777, @filename + ".cfg" + "-") FileUtils.mv(@filename + ".cfg" + "-", @filename + ".cfg", :force=>true) cmd = %{/sbin/service openshift-sni-proxy condreload} ::OpenShift::Runtime::Utils::oo_spawn(cmd, :expected_exitstatus=> 0) rescue ::OpenShift::Runtime::Utils::ShellExecutionException => e NodeLogger.logger.error("ERROR: failed to reload SNI proxy: #{e.rc}: stdout: #{e.stdout} stderr:#{e.stderr}") rescue => e NodeLogger.logger.error("ERROR: processing SNI proxy: #{e.message}") end end
Generated with the Darkfish Rdoc Generator 2.