diff --git a/README.md b/README.md index ef65931a4..228340f4a 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,10 @@ The port to use for Stomp. Boolean to install the stomp plugin. +####`tcp_keepalive` + +Boolean to enable TCP connection keepalive for RabbitMQ service. + ####`version` Sets the version to install. diff --git a/manifests/config.pp b/manifests/config.pp index c59f00d04..2795cd073 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -17,6 +17,7 @@ $node_ip_address = $rabbitmq::node_ip_address $plugin_dir = $rabbitmq::plugin_dir $port = $rabbitmq::port + $tcp_keepalive = $rabbitmq::tcp_keepalive $service_name = $rabbitmq::service_name $ssl = $rabbitmq::ssl $ssl_only = $rabbitmq::ssl_only diff --git a/manifests/init.pp b/manifests/init.pp index bad060622..f91e1afc2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -25,6 +25,7 @@ $manage_repos = $rabbitmq::params::manage_repos, $plugin_dir = $rabbitmq::params::plugin_dir, $port = $rabbitmq::params::port, + $tcp_keepalive = $rabbitmq::params::tcp_keepalive, $service_ensure = $rabbitmq::params::service_ensure, $service_manage = $rabbitmq::params::service_manage, $service_name = $rabbitmq::params::service_name, @@ -83,6 +84,7 @@ validate_re($port, ['\d+','UNSET']) validate_re($stomp_port, '\d+') validate_bool($wipe_db_on_cookie_change) + validate_bool($tcp_keepalive) # Validate service parameters. validate_re($service_ensure, '^(running|stopped)$') validate_bool($service_manage) diff --git a/manifests/params.pp b/manifests/params.pp index 81aac5483..abe7c52b7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -72,6 +72,7 @@ $node_ip_address = 'UNSET' $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" $port = '5672' + $tcp_keepalive = false $ssl = false $ssl_only = false $ssl_cacert = 'UNSET' diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index f95068412..8c9b39a26 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -474,6 +474,33 @@ end end + describe 'tcp_keepalive enabled' do + let(:params) {{ :tcp_keepalive => true }} + it 'should set tcp_listen_options keepalive true' do + should contain_file('rabbitmq.config') \ + .with_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/) + end + end + + describe 'tcp_keepalive disabled (default)' do + it 'should not set tcp_listen_options' do + should contain_file('rabbitmq.config') \ + .without_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/) + end + end + + describe 'non-bool tcp_keepalive parameter' do + let :params do + { :tcp_keepalive => 'string' } + end + + it 'should raise an error' do + expect { + should contain_file('rabbitmq.config') + }.to raise_error(Puppet::Error, /is not a boolean/) + end + end + context 'delete_guest_user' do describe 'should do nothing by default' do it { should_not contain_rabbitmq_user('guest') } diff --git a/templates/rabbitmq.config.erb b/templates/rabbitmq.config.erb index 45e63c36b..5f0bef51b 100644 --- a/templates/rabbitmq.config.erb +++ b/templates/rabbitmq.config.erb @@ -9,6 +9,9 @@ {cluster_nodes, {[<%= @r_cluster_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>], <%= @cluster_node_type %>}}, {cluster_partition_handling, <%= @cluster_partition_handling %>}, <% end -%> +<%- if @tcp_keepalive -%> + {tcp_listen_options, [{keepalive, true}]}, +<%- end -%> <%- if @ssl_only -%> {tcp_listeners, []}, <%- end -%>