loadbalancer: Implementing a proper failover based on the router state

Due to the fact that two HAProxy can not listen on the same vip at the
same time, the management of the HAProxy service has been delegated to
the keepalived process. With this patch, the keepalived process
starts/stops the HAProxy daemon based on the state is is entering.

If it enters MASTER mode then it starts the HAProxy daemon.
If it enters BACKUP mode then it stops the HAProxy daemon.

close #25
This commit is contained in:
Yanis Guenane
2014-01-13 16:43:21 -05:00
committed by Sebastien Badia
parent b4bafb06c0
commit 183b99c0d2
2 changed files with 23 additions and 10 deletions

View File

@@ -56,7 +56,9 @@ class cloud::loadbalancer(
$mysql_vip = $os_params::mysql_vip $mysql_vip = $os_params::mysql_vip
){ ){
class { 'haproxy': } class { 'haproxy':
manage_service => false,
}
class { 'keepalived': } class { 'keepalived': }
@@ -65,11 +67,13 @@ class cloud::loadbalancer(
} }
keepalived::instance { '1': keepalived::instance { '1':
interface => $keepalived_interface, interface => $keepalived_interface,
virtual_ips => split(join(flatten([$keepalived_ipvs, ['']]), " dev ${keepalived_interface},"), ','), virtual_ips => split(join(flatten([$keepalived_ipvs, ['']]), " dev ${keepalived_interface},"), ','),
state => $keepalived_state, state => $keepalived_state,
track_script => ['haproxy'], track_script => ['haproxy'],
priority => 50, priority => 50,
notify_master => '"/etc/init.d/haproxy start"',
notify_backup => '"/etc/init.d/haproxy stop"',
} }
$monitors_data = inline_template(' $monitors_data = inline_template('

View File

@@ -63,7 +63,9 @@ describe 'cloud::loadbalancer' do
end end
it 'configure haproxy server' do it 'configure haproxy server' do
should contain_class('haproxy') should contain_class('haproxy').with({
'manage_service' => 'false',
})
end end
it 'configure keepalived server' do it 'configure keepalived server' do
@@ -72,7 +74,9 @@ describe 'cloud::loadbalancer' do
it 'configure vrrp_instance with MASTER state' do it 'configure vrrp_instance with MASTER state' do
should contain_keepalived__instance('1').with({ should contain_keepalived__instance('1').with({
'state' => 'MASTER', 'state' => 'MASTER',
'notify_master' => '"/etc/init.d/haproxy start"',
'notify_backup' => '"/etc/init.d/haproxy stop"',
}) })
end end
@@ -121,7 +125,9 @@ describe 'cloud::loadbalancer' do
end end
it 'configure haproxy server' do it 'configure haproxy server' do
should contain_class('haproxy') should contain_class('haproxy').with({
'manage_service' => 'false',
})
end end
it 'configure keepalived server' do it 'configure keepalived server' do
@@ -129,7 +135,10 @@ describe 'cloud::loadbalancer' do
end end
it 'configure vrrp_instance with BACKUP state' do it 'configure vrrp_instance with BACKUP state' do
should contain_keepalived__instance('1') should contain_keepalived__instance('1').with({
'notify_master' => '"/etc/init.d/haproxy start"',
'notify_backup' => '"/etc/init.d/haproxy stop"',
})
end end
end end