Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created August 5, 2014 17:53
Show Gist options
  • Save spheromak/b3748e5015058444642c to your computer and use it in GitHub Desktop.
Save spheromak/b3748e5015058444642c to your computer and use it in GitHub Desktop.
fastmail = Services::Endpoint.new 'fastmail',
ip: '1.1.104.4',
proto: 'tcp',
port: 25
sysmail = Services::Endpoint.new 'sysmail',
ip: '1.1.104.5',
proto: 'tcp',
port: 25
uw_mailhog = Services::Endpoint.new 'uw-mailhog',
ip: '1.1.104.9',
proto: 'tcp',
port: 25
intake = Services::Endpoint.new 'intake',
ip: '1.1.104.7',
proto: 'tcp',
port: 25
endpoints = [fastmail, sysmail, intake, uw_mailhog]
endpoints.each { |e| e.save }
keepalived_vrrp 'mail' do
interface 'eth0'
state 'MASTER'
priority LB::Network.last_octet node['ipaddress']
virtual_router_id 100
virtual_ipaddress endpoints.map { |e| e.ip }
end
#
# run over the services and setup the virtual server
#
endpoints.each do |mail|
mail_service = Services::Service.new(mail.name)
log "seting up lb for service: #{mail_service.inspect}"
keepalived_virtual_server mail.name do
vs_listen_ip mail.ip
vs_listen_port mail.port.to_s
lb_algo 'wlc'
lb_kind 'dr'
vs_protocol mail.proto
# real_servers wants a hash of machines with at least "ip" and "port" keys
real_servers mail_service.members.map { |m| m.to_hash }
end
end
#
# Recipe:: _register_lb
#
# register with the service as a member
#
unless node.run_state.key? :services
log 'No services detected. cannot register this node to a mail service' do
level :warn
end
return
end
if node.run_state[:services].empty?
log 'No services found in run_state , Not registering anything' do
level :warn
end
return
end
# setup the etcd connection
Services::Connection.new run_context: run_context
node.run_state[:services].each do |service|
member = Services::Member.new node[:fqdn], service: service
# load whats been set, use those settings
member.load
# set the weight unless it's already set
member.weight = 20 unless member.weight
#
# this box is what it is. it should enforce this
# TODO: we could set this onece from chef and never
# again in the future (possibly)
member.ip = node[:ipaddress]
member.proto = 'tcp'
member.port = 25
member.save
log "Saving member for #{service}: #{member.inspect}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment