Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion resources/bin/rb_configure_leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ _RBEOF_
# External services
MODE_PG="external"
MODE_S3="external"
MODE_MEMCACHED="onpremise"
[ -f /etc/redborder/postgresql_init_conf.yml ] && MODE_PG="onpremise"
[ -f /etc/redborder/s3_init_conf.yml ] && MODE_S3="onpremise"
[ -n "${ELASTICACHE_ADDRESS}" ] && MODE_MEMCACHED="external"
cat > /var/chef/data/data_bag/rBglobal/external_services.json <<-_RBEOF_
{
"id": "external_services",
"postgresql": "$MODE_PG",
"s3": "$MODE_S3"
"s3": "$MODE_S3",
"memcached": "$MODE_MEMCACHED"
}
_RBEOF_

Expand Down
113 changes: 97 additions & 16 deletions resources/lib/rb_wiz_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize()
@devmode = { "dhcp" => "Dynamic", "static" => "Static" }
@devmodereverse = { "Dynamic" => "dhcp", "Static" => "static" }
@management_iface = nil
@sync_interface = nil
@sync_interface = nil
end

def doit(network_interfaces)
Expand Down Expand Up @@ -107,7 +107,7 @@ def get_network_interfaces
next if netdev == "lo"
netdevprop = netdev_property(netdev)
next unless (netdevprop["ID_BUS"] == "pci" and !netdevprop["MAC"].nil?)

# Fetch network scripts to get IP information
ip = get_ip_for_interface(netdev)
get_network_scripts(netdev)
Expand All @@ -118,12 +118,12 @@ def get_network_interfaces
data.item += ", IP: #{ip}" unless ip.nil? # Add IP if available
data.select = first_interface ? true : false
first_interface = false if first_interface

network_interfaces.push(data.to_a)
end
return network_interfaces
end

# Helper method to extract the IPv4 address from the network script
def get_ip_for_interface(netdev)
if File.exist?("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_ip_of_interface(interface_name)
end
nil
end

def get_netmask_of_interface(interface_name)
Socket.getifaddrs.each do |ifaddr|
if ifaddr.name == interface_name && ifaddr.addr&.ipv4?
Expand All @@ -214,15 +214,15 @@ def get_netmask_of_interface(interface_name)
def get_network_scripts(netdev)
if File.exist?("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
config_file = File.read("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")

if config_file.match(/^IPADDR=/)
ip = config_file.match(/^IPADDR=(?<ip>.*)$/)&.[](:ip)
netmask = config_file.match(/^NETMASK=(?<netmask>.*)$/)&.[](:netmask) || "255.255.255.0"
gateway = config_file.match(/^GATEWAY=(?<gateway>.*)$/)&.[](:gateway) || ""

@confdev[netdev] = {
"mode" => "static",
"ip" => ip,
"mode" => "static",
"ip" => ip,
"netmask" => netmask,
"gateway" => gateway
}
Expand Down Expand Up @@ -344,6 +344,88 @@ def doit
end
end

class MemcachedConf < WizConf

attr_accessor :conf, :cancel

def initialize()
@cancel = false
@conf = {}
end

def doit
memcached_config = {
"cfg_address"=>"",
"cfg_port"=>11211
}

loop do
dialog = MRDialog.new
dialog.clear = true
text = <<EOF

Please configure the Memcached service.

Memcached is a distributed memory object caching system that stores key-value pairs in memory.
It is used to speed up dynamic database-driven websites by caching data and objects in memory
to reduce the number of times an external data source must be read.
EOF

items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)

label = "Memcached domain:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = memcached_config[label]
data.iy = 1
data.ix = 20
data.flen = 30
data.ilen = 0
data.attr = 0
items.push(data.to_a)

label = "Memcached port:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = memcached_config[label]
data.iy = 2
data.ix = 20
data.flen = 30
data.ilen = 0
data.attr = 0
items.push(data.to_a)

dialog.title = "Memcached Configuration"
memcached_config = dialog.mixedform(text, items, 20, 60, 0)

if memcached_config.empty?
@cancel = true
break
else
break
end

dialog = MRDialog.new
dialog.clear = true
dialog.title = "Memcached Configuration Error"
text = <<EOF

An error has been detected in the Memcached configuration.

Please review the settings and ensure that the host and port are valid.
EOF
dialog.msgbox(text, 12, 60)
end
@conf['cfg_address'] = memcached_config['Memcached domain:']
@conf['cfg_port'] = memcached_config['Memcached port:']
end
end

class HostConf < WizConf

attr_accessor :conf, :cancel
Expand Down Expand Up @@ -479,7 +561,7 @@ def doit
You can set up to 3 DNS servers, but only one is mandatory. Set DNS values in order, first, second (optional) and then third (optional).

Please, insert each value fo IPv4 address in dot notation.

EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
Expand Down Expand Up @@ -597,7 +679,7 @@ def doit(sync_interface)
Please configure the synchronism network.

Select one of the device networks to designate as the synchronism network. This network is essential for connecting nodes and building the cluster. It also facilitates communication between internal services.

In some cases, the synchronism network may not have a default gateway and could be isolated from other networks.

EOF
Expand All @@ -609,7 +691,7 @@ def doit(sync_interface)
networks.each do |k,v|
data = radiolist_data.new
data.tag = k
data.item = v
data.item = v
data.select = select
if k == sync_interface
data.select = true
Expand All @@ -625,7 +707,7 @@ def doit(sync_interface)
dialog.title = "Synchronism Network configuration"

loop do
sync_interface = dialog.radiolist("Please select a network to use as the synchronism network:",
sync_interface = dialog.radiolist("Please select a network to use as the synchronism network:",
network_interfaces, 10, 80, 0)
return cancel_wizard unless sync_interface
sync_network = network_interfaces.find { |ni| ni[0] == sync_interface }[1]
Expand Down Expand Up @@ -763,7 +845,7 @@ def doit
- Unicast: Configures the Serf agent to operate in Unicast mode. In this mode, Serf attempts to join an existing cluster by scanning via ARP over the Synchronism network.

In both modes, the Synchronism network is used to identify and bind to the appropriate network device.

EOF
items = []
radiolist_data = Struct.new(:tag, :item, :select)
Expand Down Expand Up @@ -814,7 +896,7 @@ def doit
Please provide a password to encrypt Serf network traffic.

This password will prevent unauthorized nodes from connecting to the cluster. You may use any printable characters, with a length of 6 to 20 characters.

EOF

flen = 20
Expand Down Expand Up @@ -974,7 +1056,7 @@ def doit
- Password: The password for the superuser account.
- Host: The IP address or hostname of the database service.
- Port: The port for the database service (default: 5432).

Please enter these PostgreSQL parameters:

EOF
Expand Down Expand Up @@ -1191,4 +1273,3 @@ def doit
end

## vim:ts=4:sw=4:expandtab:ai:nowrap:formatoptions=croqln:

43 changes: 40 additions & 3 deletions resources/scripts/rb_setup_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def cancel_wizard()
"host" => "",
"port" => ""
},
"elasticache" => {
"cfg_address" => "",
"cfg_port" => ""
},
"mode" => "full" # default mode
}

Expand All @@ -86,15 +90,15 @@ def cancel_wizard()
text = <<EOF


This wizard will guide you through the essential steps to configure your
This wizard will guide you through the essential steps to configure your
device as a Redborder node within a Redborder cluster.

The configuration process includes the following steps:

- Network settings: Set up your network configuration
- Serf configuration: Establish Serf communication settings
- System settings: Configure the hostname, domain, and DNS
- Node mode selection: Choose the node mode, which determines
- Node mode selection: Choose the node mode, which determines
the set of services the node will run and its weight within the cluster

Would you like to proceed with the configuration?
Expand Down Expand Up @@ -131,7 +135,7 @@ def cancel_wizard()
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Error"

dialog.msgbox("Error: No network interfaces found. The script will now exit.", 0, 0)
exit
end
Expand Down Expand Up @@ -347,6 +351,33 @@ def cancel_wizard()
general_conf.delete("postgresql")
end

# External memcached configuration
text = <<EOF

Do you want to configure an external memcached service?
EOF

dialog = MRDialog.new
dialog.clear = true
dialog.title = "Confirm Configuration"
dialog.dialog_options = "--defaultno"
configure_memcached = dialog.yesno(text, 8, 50)

if configure_memcached
memconf = MemcachedConf.new
begin
memconf.doit
if memconf.cancel
cancel_wizard
else
general_conf["elasticache"] = memconf.conf
end
rescue => e
puts "Error during memcached configuration: #{e.message}"
end
else
general_conf.delete("elasticache")
end

# Set mode
modeconf = ModeConf.new
Expand Down Expand Up @@ -401,6 +432,12 @@ def cancel_wizard()
text += " port: #{general_conf["postgresql"]["port"]}\n"
end

unless general_conf["elasticache"].nil?
text += "\n- Elasticache:\n"
text += " Domain: #{general_conf["elasticache"]["cfg_address"]}\n"
text += " Port: #{general_conf["elasticache"]["cfg_port"]}\n"
end

text += "\n- Serf:\n"
text += " mode: #{general_conf["serf"]["multicast"] ? "multicast" : "unicast"}\n"
unless general_conf["serf"]["sync_net"].nil? || general_conf["serf"]["sync_net"].empty?
Expand Down