Skip to content

Commit

Permalink
Merge pull request #309 from buzzdeee/master
Browse files Browse the repository at this point in the history
Add Support for OpenBSD and fix rabbitmq_exchange/rabbitmqadmin.rb
  • Loading branch information
cmurphy committed Feb 23, 2015
2 parents 1ad0a6e + 1e685b4 commit 50b9eb3
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 42 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 11 additions & 21 deletions lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions lib/puppet/type/rabbitmq_erlang_cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'],
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -183,6 +186,7 @@
}

Class['::rabbitmq::service'] -> Class['::rabbitmq::install::rabbitmqadmin']
Class['::rabbitmq::install::rabbitmqadmin'] -> Rabbitmq_exchange<| |>
}

if $stomp_ensure {
Expand Down Expand Up @@ -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<| |>

}
6 changes: 3 additions & 3 deletions manifests/install/rabbitmqadmin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
}
Expand Down
27 changes: 26 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,53 @@
$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'
$package_name = 'rabbitmq-server'
$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'
$package_name = 'rabbitmq-server'
$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'
$package_name = 'rabbitmq-server'
$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.")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 50b9eb3

Please sign in to comment.