diff --git a/README.md b/README.md index 258f9bf13..781061d4e 100644 --- a/README.md +++ b/README.md @@ -381,6 +381,18 @@ repository otherwise. Boolean to determine if we should DESTROY AND DELETE the RabbitMQ database. +####`rabbitmq_user` + +String: OS dependent, default defined in param.pp. The system user the rabbitmq daemon runs as. + +####`rabbitmq_group` + +String: OS dependent, default defined in param.pp. The system group the rabbitmq daemon runs as. + +####`rabbitmq_home` + +String: OS dependent. default defined in param.pp. The home directory of the rabbitmq deamon. + ##Native Types ### rabbitmq\_user @@ -493,9 +505,9 @@ rabbitmq_plugin {'rabbitmq_stomp': This is essentially a private type used by the rabbitmq::config class to manage the erlang cookie. It replaces the rabbitmq_erlang_cookie fact from earlier versions of this module. It manages the content of the cookie -usually located at /var/lib/rabbitmq/.erlang.cookie, which includes +usually located at "${rabbitmq_home}/.erlang.cookie", which includes stopping the rabbitmq service and wiping out the database at -/var/lib/rabbitmq/mnesia if the user agrees to it. We don't recommend using +"${rabbitmq_home}/mnesia" if the user agrees to it. We don't recommend using this type directly. ##Limitations diff --git a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb index 6e05b7811..58c8b3c96 100644 --- a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb +++ b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb @@ -16,12 +16,12 @@ def exists? def content=(value) if resource[:force] == :true # Danger! puppet('resource', 'service', resource[:service_name], 'ensure=stopped') - FileUtils.rm_rf('/var/lib/rabbitmq/mnesia') + FileUtils.rm_rf(resource[:rabbitmq_home] + File::PATH_SEPARATOR + 'mnesia') File.open(resource[:path], 'w') do |cookie| cookie.chmod(0400) cookie.write(value) end - FileUtils.chown('rabbitmq', 'rabbitmq', resource[:path]) + FileUtils.chown(resource[:rabbitmq_user], resource[:rabbitmq_group], resource[:path]) else fail("The current erlang cookie needs to change. In order to do this the RabbitMQ database needs to be wiped. Please set force => true to allow this to happen automatically.") end diff --git a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb index f9ea3d286..3651dc9cf 100644 --- a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb @@ -25,38 +25,28 @@ def should_vhost def self.all_vhosts vhosts = [] - parse_command( - self.run_with_retries { - rabbitmqctl('list_vhosts') - } - ).collect do |vhost| - vhosts.push(vhost) + self.run_with_retries { + rabbitmqctl('-q', 'list_vhosts') + }.split(/\n/).each do |vhost| + vhosts.push(vhost) end vhosts end def self.all_exchanges(vhost) exchanges = [] - parse_command( - self.run_with_retries { - rabbitmqctl('list_exchanges', '-p', vhost, 'name', 'type') - } - ) - end - - def self.parse_command(cmd_output) - # first line is: - # Listing exchanges/vhosts ... - # while the last line is - # ...done. - # - cmd_output.split(/\n/)[1..-2] + self.run_with_retries { + rabbitmqctl('-q', 'list_exchanges', '-p', vhost, 'name', 'type') + }.split(/\n/).each do |exchange| + exchanges.push(exchange) + end + exchanges end def self.instances resources = [] all_vhosts.each do |vhost| - all_exchanges(vhost).collect do |line| + all_exchanges(vhost).each do |line| name, type = line.split() if type.nil? # if name is empty, it will wrongly get the type's value. diff --git a/lib/puppet/type/rabbitmq_erlang_cookie.rb b/lib/puppet/type/rabbitmq_erlang_cookie.rb index 564af5253..c2e5898dc 100644 --- a/lib/puppet/type/rabbitmq_erlang_cookie.rb +++ b/lib/puppet/type/rabbitmq_erlang_cookie.rb @@ -16,6 +16,18 @@ def change_to_s(current, desired) newvalues(:true, :false) end + newparam(:rabbitmq_user) do + defaultto('rabbitmq') + end + + newparam(:rabbitmq_group) do + defaultto('rabbitmq') + end + + newparam(:rabbitmq_home) do + defaultto('/var/lib/rabbitmq') + end + newparam(:service_name) do newvalues(/^\S+$/) end diff --git a/manifests/config.pp b/manifests/config.pp index c111dab5b..be7169d38 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -18,6 +18,9 @@ $management_port = $rabbitmq::management_port $node_ip_address = $rabbitmq::node_ip_address $plugin_dir = $rabbitmq::plugin_dir + $rabbitmq_user = $rabbitmq::rabbitmq_user + $rabbitmq_group = $rabbitmq::rabbitmq_group + $rabbitmq_home = $rabbitmq::rabbitmq_home $port = $rabbitmq::port $tcp_keepalive = $rabbitmq::tcp_keepalive $service_name = $rabbitmq::service_name @@ -100,12 +103,15 @@ if $erlang_cookie == undef { fail('You must set the $erlang_cookie value in order to configure clustering.') } else { - rabbitmq_erlang_cookie { '/var/lib/rabbitmq/.erlang.cookie': - content => $erlang_cookie, - force => $wipe_db_on_cookie_change, - service_name => $service_name, - before => File['rabbitmq.config'], - notify => Class['rabbitmq::service'], + rabbitmq_erlang_cookie { "${rabbitmq_home}/.erlang.cookie": + content => $erlang_cookie, + force => $wipe_db_on_cookie_change, + rabbitmq_user => $rabbitmq_user, + rabbitmq_group => $rabbitmq_group, + rabbitmq_home => $rabbitmq_home, + service_name => $service_name, + before => File['rabbitmq.config'], + notify => Class['rabbitmq::service'], } } } diff --git a/manifests/init.pp b/manifests/init.pp index 138515ee3..d4a331934 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -25,6 +25,9 @@ $repos_ensure = $rabbitmq::params::repos_ensure, $manage_repos = $rabbitmq::params::manage_repos, $plugin_dir = $rabbitmq::params::plugin_dir, + $rabbitmq_user = $rabbitmq::params::rabbitmq_user, + $rabbitmq_group = $rabbitmq::params::rabbitmq_group, + $rabbitmq_home = $rabbitmq::params::rabbitmq_home, $port = $rabbitmq::params::port, $tcp_keepalive = $rabbitmq::params::tcp_keepalive, $service_ensure = $rabbitmq::params::service_ensure, @@ -183,6 +186,7 @@ } Class['::rabbitmq::service'] -> Class['::rabbitmq::install::rabbitmqadmin'] + Class['::rabbitmq::install::rabbitmqadmin'] -> Rabbitmq_exchange<| |> } if $stomp_ensure { @@ -212,6 +216,5 @@ # Make sure the various providers have their requirements in place. Class['::rabbitmq::install'] -> Rabbitmq_plugin<| |> - Class['::rabbitmq::install::rabbitmqadmin'] -> Rabbitmq_exchange<| |> } diff --git a/manifests/install/rabbitmqadmin.pp b/manifests/install/rabbitmqadmin.pp index 5b9f527b9..bf545eea4 100644 --- a/manifests/install/rabbitmqadmin.pp +++ b/manifests/install/rabbitmqadmin.pp @@ -13,7 +13,7 @@ $protocol = $rabbitmq::ssl ? { false => 'http', default => 'https' } staging::file { 'rabbitmqadmin': - target => '/var/lib/rabbitmq/rabbitmqadmin', + target => "${rabbitmq::rabbitmq_home}/rabbitmqadmin", source => "${protocol}://${default_user}:${default_pass}@localhost:${management_port}/cli/rabbitmqadmin", curl_option => '-k --noproxy localhost --retry 30 --retry-delay 6', timeout => '180', @@ -26,8 +26,8 @@ file { '/usr/local/bin/rabbitmqadmin': owner => 'root', - group => 'root', - source => '/var/lib/rabbitmq/rabbitmqadmin', + group => '0', + source => "${rabbitmq::rabbitmq_home}/rabbitmqadmin", mode => '0755', require => Staging::File['rabbitmqadmin'], } diff --git a/manifests/params.pp b/manifests/params.pp index f57b1f9c0..b09d7620a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,6 +10,10 @@ $package_name = 'rabbitmq' $service_name = 'rabbitmq' $version = '3.1.3-1' + $rabbitmq_user = 'rabbitmq' + $rabbitmq_group = 'rabbitmq' + $rabbitmq_home = '/var/lib/rabbitmq' + $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" } 'Debian': { $package_ensure = 'installed' @@ -17,6 +21,20 @@ $service_name = 'rabbitmq-server' $package_provider = 'apt' $version = '3.1.5' + $rabbitmq_user = 'rabbitmq' + $rabbitmq_group = 'rabbitmq' + $rabbitmq_home = '/var/lib/rabbitmq' + $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" + } + 'OpenBSD': { + $package_ensure = 'installed' + $package_name = 'rabbitmq' + $service_name = 'rabbitmq' + $version = '3.4.2' + $rabbitmq_user = '_rabbitmq' + $rabbitmq_group = '_rabbitmq' + $rabbitmq_home = '/var/rabbitmq' + $plugin_dir = '/usr/local/lib/rabbitmq/plugins' } 'RedHat': { $package_ensure = 'installed' @@ -24,6 +42,10 @@ $service_name = 'rabbitmq-server' $package_provider = 'rpm' $version = '3.1.5-1' + $rabbitmq_user = 'rabbitmq' + $rabbitmq_group = 'rabbitmq' + $rabbitmq_home = '/var/lib/rabbitmq' + $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" } 'SUSE': { $package_ensure = 'installed' @@ -31,6 +53,10 @@ $service_name = 'rabbitmq-server' $package_provider = 'zypper' $version = '3.1.5-1' + $rabbitmq_user = 'rabbitmq' + $rabbitmq_group = 'rabbitmq' + $rabbitmq_home = '/var/lib/rabbitmq' + $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" } default: { fail("The ${module_name} module is not supported on an ${::osfamily} based system.") @@ -61,7 +87,6 @@ $erlang_cookie = undef $interface = 'UNSET' $node_ip_address = 'UNSET' - $plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins" $port = '5672' $tcp_keepalive = false $ssl = false diff --git a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb index 89d6e94e3..6e956fe8b 100644 --- a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb @@ -14,13 +14,10 @@ end it 'should return instances' do - provider_class.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT -Listing vhosts ... + provider_class.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT / -...done. EOT - provider_class.expects(:rabbitmqctl).with('list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT -Listing exchanges ... + provider_class.expects(:rabbitmqctl).with('-q', 'list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT direct amq.direct direct amq.fanout fanout @@ -29,7 +26,6 @@ amq.rabbitmq.log topic amq.rabbitmq.trace topic amq.topic topic - ...done. EOT instances = provider_class.instances instances.size.should == 8