From ca4f4b90a5adb7ab18d5d99d14b29377c7fb1512 Mon Sep 17 00:00:00 2001 From: Kevin Nuckolls Date: Thu, 24 May 2012 11:02:17 -0500 Subject: [PATCH 1/4] Added fix that installs the correct version --- recipes/default.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/default.rb b/recipes/default.rb index 9f508e9b..15700fcf 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -4,6 +4,7 @@ # # Copyright 2009, Benjamin Black # Copyright 2009-2011, Opscode, Inc. +# Copyright 2012, Kevin Nuckolls # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,6 +49,7 @@ components ["main"] key "http://www.rabbitmq.com/rabbitmq-signing-key-public.asc" action :add + notifies :run, resources(:execute => "apt-get update"), :immediately end package "rabbitmq-server" when "redhat", "centos", "scientific" From 667476dd670a52bfa4ed6190aab63745f3716393 Mon Sep 17 00:00:00 2001 From: Kevin Nuckolls Date: Thu, 24 May 2012 11:17:19 -0500 Subject: [PATCH 2/4] Fixed it so that the RabbitMQ process will daemonize properly You'll see setsid used in all the init statements in this cookbook. This is because there is a problem with the stock init script in the RabbitMQ debian package (at least in 2.8.2) that makes it not daemonize properly when called from chef. The setsid command forces the subprocess into a state where it can daemonize properly. (thanks to Daniel DeLeo for the help) --- recipes/default.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 15700fcf..054535d0 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -19,11 +19,6 @@ # limitations under the License. # -# rabbitmq-server is not well-behaved as far as managed services goes -# we'll need to add a LWRP for calling rabbitmqctl stop -# while still using /etc/init.d/rabbitmq-server start -# because of this we just put the rabbitmq-env.conf in place and let it rip - directory "/etc/rabbitmq/" do owner "root" group "root" @@ -51,6 +46,8 @@ action :add notifies :run, resources(:execute => "apt-get update"), :immediately end + # installs the required setsid command -- should be there by default but just in case + package "util-linux" package "rabbitmq-server" when "redhat", "centos", "scientific" remote_file "/tmp/rabbitmq-server-2.6.1-1.noarch.rpm" do @@ -82,8 +79,17 @@ notifies :restart, "service[rabbitmq-server]", :immediately end +## You'll see setsid used in all the init statements in this cookbook. This +## is because there is a problem with the stock init script in the RabbitMQ +## debian package (at least in 2.8.2) that makes it not daemonize properly +## when called from chef. The setsid command forces the subprocess into a state +## where it can daemonize properly. -Kevin (thanks to Daniel DeLeo for the help) + service "rabbitmq-server" do - stop_command "/usr/sbin/rabbitmqctl stop" + start_command "setsid /etc/init.d/rabbitmq-server start" + stop_command "setsid /etc/init.d/rabbitmq-server stop" + restart_command "setsid /etc/init.d/rabbitmq-server restart" + status_command "setsid /etc/init.d/rabbitmq-server status" supports :status => true, :restart => true action [ :enable, :start ] end From fd1021ffea61acb4fe56550b4bce86811d5adfca Mon Sep 17 00:00:00 2001 From: Kevin Nuckolls Date: Thu, 24 May 2012 14:28:36 -0500 Subject: [PATCH 3/4] Correctly set the erlang key based on the attribute The previous code wouldn't ever fire. The deb package creates a random erlang key and the template has a not_if File.exists for that key. --- recipes/default.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 054535d0..08904847 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -59,15 +59,28 @@ end end -if node[:rabbitmq][:cluster] - # If this already exists, don't do anything - # Changing the cookie will stil have to be a manual process +if File.exists?('/var/lib/rabbitmq/.erlang.cookie') + @existing_erlang_key = File.read('/var/lib/rabbitmq/.erlang.cookie') +else + @existing_erlang_key = "" +end + +if node[:rabbitmq][:cluster] and node[:rabbitmq][:erlang_cookie] != @existing_erlang_key + execute "rabbitmq-stop" do + command "setsid /etc/init.d/rabbitmq-server stop" + action :run + end + template "/var/lib/rabbitmq/.erlang.cookie" do source "doterlang.cookie.erb" owner "rabbitmq" group "rabbitmq" mode 0400 - not_if { File.exists? "/var/lib/rabbitmq/.erlang.cookie" } + end + + execute "rabbitmq-start" do + command "setsid /etc/init.d/rabbitmq-server start" + action :run end end From c4f3d4063828abbfc09d26404435027cfc26c8ee Mon Sep 17 00:00:00 2001 From: Kevin Nuckolls Date: Thu, 12 Jul 2012 14:14:35 -0500 Subject: [PATCH 4/4] added attribute for erlang cookie path --- attributes/default.rb | 1 + recipes/default.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 79fac2f1..e5120d5f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,6 +23,7 @@ default[:rabbitmq][:cluster] = false default[:rabbitmq][:cluster_disk_nodes] = [] default[:rabbitmq][:erlang_cookie] = 'AnyAlphaNumericStringWillDo' +default[:rabbitmq][:erlang_cookie_path] = '/var/lib/rabbitmq/.erlang.cookie' #ssl default[:rabbitmq][:ssl] = false diff --git a/recipes/default.rb b/recipes/default.rb index bb214f74..a5e4cd3b 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -62,8 +62,8 @@ end end -if File.exists?('/var/lib/rabbitmq/.erlang.cookie') - existing_erlang_key = File.read('/var/lib/rabbitmq/.erlang.cookie') +if File.exists?(node[:rabbitmq][:erlang_cookie_path]) + existing_erlang_key = File.read(node[:rabbitmq][:erlang_cookie_path]) else existing_erlang_key = "" end