Skip to content

Commit

Permalink
Merge pull request #4 from redBorder/development
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
malvads authored Oct 1, 2024
2 parents 263e155 + 3d28eb4 commit 350e832
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
cookbook-keepalived CHANGELOG
===============

## 0.1.0

- David Vanhoucke
- [cfd2c8a] trigger notify scripts to add or remove iptables rules

## 0.0.2

- Miguel Negron
Expand Down
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
maintainer_email 'dvanhoucke@redborder.com'
license 'All rights reserved'
description 'Installs/Configures cookbook-keepalived'
version '0.0.2'
version '0.1.0'
22 changes: 22 additions & 0 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@
notifies :reload, 'service[keepalived]', :delayed
end

unless virtual_ips['external']['webui']['ip'].nil?
template '/usr/lib/redborder/bin/rb_keepalived_master_notify_webui.sh' do
cookbook 'keepalived'
source 'notify.erb'
owner 'root'
group 'root'
mode '0755'
retries 2
variables(vip: virtual_ips['external']['webui']['ip'])
end

template '/usr/lib/redborder/bin/rb_keepalived_backup_notify_webui.sh' do
cookbook 'keepalived'
source 'notify.erb'
owner 'root'
group 'root'
mode '0755'
retries 2
variables(vip: virtual_ips['external']['webui']['ip'])
end
end

template '/etc/keepalived/keepalived.conf' do
cookbook 'keepalived'
source 'keepalived.conf.erb'
Expand Down
8 changes: 6 additions & 2 deletions resources/templates/default/keepalived.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ global_defs {
}
notification_email_from redborder
router_id redborder_manager_cluster
script_user keepalived
script_user root
enable_script_security
}

Expand Down Expand Up @@ -44,7 +44,7 @@ vrrp_instance vi_<%= ip %> {
state BACKUP
interface <%= iface %>
virtual_router_id <%= ((@start_id.nil? ? 111 : @start_id.to_i) + index).to_s %>
priority <%= ( services.select{ |x| x["service"]=="postgresql" }.nil? ? "100" : (File.exists?("/opt/rb/var/pgdata/postgresql.conf") ? "100" : "50" ) ) %>
priority <%= 50+@managers.size-@managers.index { |m| m.name == node.name } %>
advert_int 1
nopreempt
<% if !node["redborder"].nil? and !node["redborder"]["dmidecode"].nil? and !node["redborder"]["dmidecode"]["manufacturer"].nil? and node["redborder"]["dmidecode"]["manufacturer"].to_s.downcase == "xen" %>
Expand Down Expand Up @@ -91,6 +91,10 @@ vrrp_instance vi_<%= ip %> {
virtual_ipaddress {
<%= ip %>/32
}
<% if services.select{ |x| x["service"]=="webui" } %>
notify_master "/usr/lib/redborder/bin/rb_keepalived_master_notify_webui.sh"
notify_backup "/usr/lib/redborder/bin/rb_keepalived_backup_notify_webui.sh"
<% end %>
}
<% end %>
<% end %>
Expand Down
9 changes: 9 additions & 0 deletions resources/templates/default/notify.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if hostname -I | grep -q <%= @vip %>; then
iptables -t nat -D PREROUTING -d <%= @vip %> -j REDIRECT &>/dev/null
else
if ! iptables -t nat -C PREROUTING -d <%= @vip %> -j REDIRECT 2>/dev/null; then
iptables -t nat -A PREROUTING -d <%= @vip %> -j REDIRECT
fi
fi

0 comments on commit 350e832

Please sign in to comment.