Skip to content

Commit

Permalink
add keepalived and balanced services
Browse files Browse the repository at this point in the history
  • Loading branch information
davidredborder committed Jun 10, 2024
1 parent 73d52cb commit 32fe52b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 17 deletions.
7 changes: 7 additions & 0 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
default["redborder"]["services"]["n2klocd"] = false
default["redborder"]["services"]["radiusd"] = false
default["redborder"]["services"]["postfix"] = true
default["redborder"]["services"]["keepalived"] = false

default["redborder"]["systemdservices"]["chef-client"] = ["chef-client"]
default["redborder"]["systemdservices"]["chef-server"] = ["opscode-erchef"]
Expand Down Expand Up @@ -211,11 +212,17 @@
default["redborder"]["systemdservices"]["n2klocd"] = ["n2klocd"]
default["redborder"]["systemdservices"]["radiusd"] = ["radiusd"]
default["redborder"]["systemdservices"]["postfix"] = ["postfix"]
default["redborder"]["systemdservices"]["keepalived"] = ["keepalived"]

default["redborder"]["manager"]["balanced"] = [ {:port => 443, :protocol => "tcp", :name => "redborder webui", :service => "webui", :redirected_service=> "nginx", :persistence_timeout => 9600}, {:port => 2055, :protocol => "udp", :name => "netflow,ipfix/sflow daemon", :service => "f2k", :redirected_service=> "f2k", :persistence_timeout => 30}, {:port => 6343, :protocol => "udp", :name => "sflow daemon", :service => "sfacctd", :redirected_service=> "sfacctd", :persistence_timeout => 30}, {:port => 9092, :protocol => "tcp", :name => "kafka", :service => "kafka", :redirected_service=> "kafka", :persistence_timeout => 30} ]

# Tier
default["redborder"]["druid"]["historical"]["tier"] = "default"
default["redborder"]["druid"]["historical"]["maxsize"] = -1

#Virtual Ips
default["redborder"]["manager"]["virtual_ips"] = { :external => [ {:service => "webui", "deps" => ["nginx"]}, {:service => "f2k"}, {:service => "sfacctd"}, {:service => "kafka"} ] }

# Realtime
default["redborder"]["druid"]["realtime"]["partition_num"] = 0

Expand Down
17 changes: 3 additions & 14 deletions resources/libraries/get_managers_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,9 @@ def get_managers_all
managers_keys.each do |m_key|
m = Chef::Node.load m_key
m = node if m.name == node.name
begin
roles = m.roles
rescue NoMethodError
begin
roles = m.run_list
rescue
roles = []
end
end
unless roles.nil?
if roles.include?("manager")
managers << m
end
end
if m.role?("manager")
managers << m
end
end
managers
end
Expand Down
1 change: 1 addition & 0 deletions resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
depends 'rblogstatter'
depends 'rb-arubacentral'
depends 'rb-postfix'
depends 'keepalived'
22 changes: 21 additions & 1 deletion resources/recipes/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
# Services configuration

# manager services
manager_services = manager_services()
managers = node.run_state['managers']
manager_services = node.run_state['manager_services']
node.default["redborder"]["manager"]["services"]["current"] = node.run_state['manager_services']
virtual_ips = node.run_state['virtual_ips']
virtual_ips_per_ip = node.run_state['virtual_ips_per_ip']

rb_common_config "Configure common" do
action :configure
Expand Down Expand Up @@ -49,6 +53,22 @@
end
end

vrrp_secrets = Chef::DataBagItem.load("passwords", "vrrp") rescue vrrp_secrets = {}
keepalived_config "Configure keepalived" do
vrrp_secrets vrrp_secrets
virtual_ips virtual_ips
virtual_ips_per_ip virtual_ips_per_ip
managers managers
balanced_services node["redborder"]["manager"]["balanced"]
has_any_virtual_ip node.run_state['has_any_virtual_ip']
manager_services manager_services
ipmgt node["ipaddress"]
iface_management node["redborder"]["management_interface"]
ipaddress_sync node["ipaddress_sync"]
managers_per_service node["redborder"]["managers_per_services"]
action (manager_services["keepalived"] ? :add : :remove)
end

zookeeper_config "Configure Zookeeper" do
port node["zookeeper"]["port"]
memory node["redborder"]["memory_services"]["zookeeper"]["memory"]
Expand Down
39 changes: 37 additions & 2 deletions resources/recipes/prepare_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@
node.default["redborder"]["cdomain"] = cdomain

#get managers information(name, ip, services...)
node.default["redborder"]["cluster_info"] = get_cluster_info()
node.default["redborder"]["cluster_info"] = get_cluster_info

# manager services
node.run_state['manager_services'] = manager_services()
node.default["redborder"]["manager"]["services"]["current"] = node.run_state['manager_services']

#get managers sorted by service
node.default["redborder"]["managers_per_services"] = managers_per_service()
node.default["redborder"]["managers_per_services"] = managers_per_service

#get elasticache nodes
elasticache = Chef::DataBagItem.load("rBglobal", "elasticache") rescue elasticache = {}
Expand Down Expand Up @@ -101,6 +105,37 @@
#get namespaces
node.default["redborder"]["namespaces"] = get_namespaces

node.run_state['managers'] = get_managers_all

# keepalived
# Update keepalived status
node.run_state['has_balanced_service_enable']=false
if node.run_state['manager_services']["keepalived"]
node.run_state['has_balanced_service_enable']=true
else
if !node["redborder"]["manager"]["balanced"].nil?
node["redborder"]["manager"]["balanced"].each do |s|
node.run_state['has_balanced_service_enable']=true if node.run_state['manager_services'][s[:service]]
end
end
end
node.run_state['virtual_ips'], node.run_state['has_any_virtual_ip'] = get_virtual_ip_info(node.run_state['managers'])
node.run_state['virtual_ips_per_ip'] = get_virtual_ips_per_ip_info(node.run_state['virtual_ips'])
if File.exist?"/etc/lock/keepalived"
node.run_state['manager_services']["keepalived"] = false
else
if node["redborder"].nil? or node["redborder"]["dmidecode"].nil? or node["redborder"]["dmidecode"]["manufacturer"].nil? or node["redborder"]["dmidecode"]["manufacturer"].to_s.downcase == "xen"
if manager_index>0 and !cluster_installed
node.run_state['manager_services']["keepalived"] = false
else
node.run_state['manager_services']["keepalived"] = node.run_state['has_any_virtual_ip'] and !File.exist?"/etc/lock/keepalived"
end
else
node.run_state['manager_services']["keepalived"] = node.run_state['has_any_virtual_ip'] and !File.exist?"/etc/lock/keepalived"
end
end


#get string with all zookeeper hosts and port separated by commas, its needed for multiples services
zk_port = node["redborder"]["zookeeper"]["port"]
#zk_hosts = node["redborder"]["managers_per_services"]["zookeeper"].map {|z| "#{z}.node:#{zk_port}"}.join(',')
Expand Down

0 comments on commit 32fe52b

Please sign in to comment.