From a253ca0e795cbee107f0ba38b58b07e825f4e907 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Wed, 10 Jul 2013 17:49:35 +0200 Subject: [PATCH 1/4] Clean recipe in chef way use 2 spaces ... --- recipes/default.rb | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index c108a1f..478566e 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -6,33 +6,33 @@ # package "beanstalkd" do - action :upgrade + action :upgrade end case node[:platform] - when "debian", "ubuntu" - template_path = "/etc/default/beanstalkd" #templates/ubuntu - else - template_path = "/etc/sysconfig/beanstalkd" #templates/default +when "debian", "ubuntu" + template_path = "/etc/default/beanstalkd" #templates/ubuntu +else + template_path = "/etc/sysconfig/beanstalkd" #templates/default end template "#{template_path}" do - source "beanstalkd.erb" - owner "root" - group "root" - mode 0640 - variables( - :opts => node[:beanstalkd][:opts], - :start_during_boot => node[:beanstalkd][:start_during_boot] - ) - notifies :restart, "service[beanstalkd]" + source "beanstalkd.erb" + owner "root" + group "root" + mode 0640 + variables( + :opts => node[:beanstalkd][:opts], + :start_during_boot => node[:beanstalkd][:start_during_boot] + ) + notifies :restart, "service[beanstalkd]" end service "beanstalkd" do - start_command "/etc/init.d/beanstalkd start" - stop_command "/etc/init.d/beanstalkd stop" - status_command "/etc/init.d/beanstalkd status" - supports [:start, :stop, :status] - #starts the service if it's not running and enables it to start at system boot time - action [:enable, :start] -end \ No newline at end of file + start_command "/etc/init.d/beanstalkd start" + stop_command "/etc/init.d/beanstalkd stop" + status_command "/etc/init.d/beanstalkd status" + supports [:start, :stop, :status] + #starts the service if it's not running and enables it to start at system boot time + action [:enable, :start] +end From 74f34f602875d921636d107481cb6486f3f7140b Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Wed, 10 Jul 2013 17:51:18 +0200 Subject: [PATCH 2/4] use string instead of symbol --- attributes/default.rb | 4 ++-- recipes/default.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 74fc238..ab3c614 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,7 +5,7 @@ # Copyright 2012-2013, Escape Studios # -default[:beanstalkd][:opts] = {} +default["beanstalkd"]["opts"] = {} #Ubuntu only -default[:beanstalkd][:start_during_boot] = false \ No newline at end of file +default["beanstalkd"]["start_during_boot"] = false diff --git a/recipes/default.rb b/recipes/default.rb index 478566e..0923480 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -9,7 +9,7 @@ action :upgrade end -case node[:platform] +case node["platform"] when "debian", "ubuntu" template_path = "/etc/default/beanstalkd" #templates/ubuntu else @@ -22,8 +22,8 @@ group "root" mode 0640 variables( - :opts => node[:beanstalkd][:opts], - :start_during_boot => node[:beanstalkd][:start_during_boot] + :opts => node["beanstalkd"]["opts"], + :start_during_boot => node["beanstalkd"]["start_during_boot"] ) notifies :restart, "service[beanstalkd]" end From 715a6b9de54d378c21076051c373204ee092d692 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Wed, 10 Jul 2013 17:58:36 +0200 Subject: [PATCH 3/4] Refactor template part In this way we manage any rhel distrib and any debian like --- attributes/default.rb | 2 + recipes/default.rb | 44 +++++++++++-------- .../beanstalkd.default.erb} | 0 ...eanstalkd.erb => beanstalkd.sysconfig.erb} | 0 templates/ubuntu/beanstalkd.erb | 13 ------ 5 files changed, 28 insertions(+), 31 deletions(-) rename templates/{debian/beanstalkd.erb => default/beanstalkd.default.erb} (100%) rename templates/default/{beanstalkd.erb => beanstalkd.sysconfig.erb} (100%) delete mode 100644 templates/ubuntu/beanstalkd.erb diff --git a/attributes/default.rb b/attributes/default.rb index ab3c614..1179802 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -9,3 +9,5 @@ #Ubuntu only default["beanstalkd"]["start_during_boot"] = false + +default["beanstalkd"]["upgrade"] = true diff --git a/recipes/default.rb b/recipes/default.rb index 0923480..dec7260 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -6,26 +6,34 @@ # package "beanstalkd" do - action :upgrade + action :upgrade if node["beanstalkd"]["upgrade"] end -case node["platform"] -when "debian", "ubuntu" - template_path = "/etc/default/beanstalkd" #templates/ubuntu -else - template_path = "/etc/sysconfig/beanstalkd" #templates/default -end - -template "#{template_path}" do - source "beanstalkd.erb" - owner "root" - group "root" - mode 0640 - variables( - :opts => node["beanstalkd"]["opts"], - :start_during_boot => node["beanstalkd"]["start_during_boot"] - ) - notifies :restart, "service[beanstalkd]" +case node["platform_family"] +when "debian" + template "beanstalkd default file" do + source "beanstalkd.default.erb" + path "/etc/default/beanstalkd" + owner "root" + group "root" + mode 0640 + variables( + :opts => node["beanstalkd"]["opts"], + :start_during_boot => node["beanstalkd"]["start_during_boot"] + ) + end +when "rhel" + template "beanstalkd sysconfig file" do + source "beanstalkd.sysconfig.erb" + path "/etc/sysconfig/beanstalkd" + owner "root" + group "root" + mode 0640 + variables( + :opts => node["beanstalkd"]["opts"] + ) + notifies :restart, "service[beanstalkd]" + end end service "beanstalkd" do diff --git a/templates/debian/beanstalkd.erb b/templates/default/beanstalkd.default.erb similarity index 100% rename from templates/debian/beanstalkd.erb rename to templates/default/beanstalkd.default.erb diff --git a/templates/default/beanstalkd.erb b/templates/default/beanstalkd.sysconfig.erb similarity index 100% rename from templates/default/beanstalkd.erb rename to templates/default/beanstalkd.sysconfig.erb diff --git a/templates/ubuntu/beanstalkd.erb b/templates/ubuntu/beanstalkd.erb deleted file mode 100644 index 4707bc5..0000000 --- a/templates/ubuntu/beanstalkd.erb +++ /dev/null @@ -1,13 +0,0 @@ -# -# /etc/default/beanstalkd -# -# Generated by Chef for <%= node[:fqdn] %> -# - -## Defaults for the beanstalkd init script, /etc/init.d/beanstalkd on -## Debian systems. Append ``-b /var/lib/beanstalkd'' for persistent -## storage. -DAEMON_OPTS="<% @opts.each do |k,v| %><%= "-#{k} #{v}" %> <% end %>" - -## Uncomment to enable startup during boot. -<% unless @start_during_boot %>#<% end %>START=yes \ No newline at end of file From 970ab87de6ab02133e7ed778835add693be75489 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Wed, 10 Jul 2013 18:12:23 +0200 Subject: [PATCH 4/4] new way to manage recipes. Each recipe do a single porpose. It allow cookbook to be extand easily. --- attributes/default.rb | 1 + recipes/conf.rb | 26 +++++++++++++++++++++++ recipes/default.rb | 43 ++++---------------------------------- recipes/install.rb | 1 + recipes/install_package.rb | 3 +++ recipes/repo.rb | 10 +++++++++ recipes/service.rb | 5 +++++ 7 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 recipes/conf.rb create mode 100644 recipes/install.rb create mode 100644 recipes/install_package.rb create mode 100644 recipes/repo.rb create mode 100644 recipes/service.rb diff --git a/attributes/default.rb b/attributes/default.rb index 1179802..82480e1 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -11,3 +11,4 @@ default["beanstalkd"]["start_during_boot"] = false default["beanstalkd"]["upgrade"] = true +default["beanstalkd"]["repo"] = false diff --git a/recipes/conf.rb b/recipes/conf.rb new file mode 100644 index 0000000..03c3918 --- /dev/null +++ b/recipes/conf.rb @@ -0,0 +1,26 @@ +case node["platform_family"] +when "debian" + template "beanstalkd default file" do + source "beanstalkd.default.erb" + path "/etc/default/beanstalkd" + owner "root" + group "root" + mode 0640 + variables( + :opts => node["beanstalkd"]["opts"], + :start_during_boot => node["beanstalkd"]["start_during_boot"] + ) + end +when "rhel" + template "beanstalkd sysconfig file" do + source "beanstalkd.sysconfig.erb" + path "/etc/sysconfig/beanstalkd" + owner "root" + group "root" + mode 0640 + variables( + :opts => node["beanstalkd"]["opts"] + ) + notifies :restart, "service[beanstalkd]" + end +end diff --git a/recipes/default.rb b/recipes/default.rb index dec7260..84d24a8 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -5,42 +5,7 @@ # Copyright 2012-2013, Escape Studios # -package "beanstalkd" do - action :upgrade if node["beanstalkd"]["upgrade"] -end - -case node["platform_family"] -when "debian" - template "beanstalkd default file" do - source "beanstalkd.default.erb" - path "/etc/default/beanstalkd" - owner "root" - group "root" - mode 0640 - variables( - :opts => node["beanstalkd"]["opts"], - :start_during_boot => node["beanstalkd"]["start_during_boot"] - ) - end -when "rhel" - template "beanstalkd sysconfig file" do - source "beanstalkd.sysconfig.erb" - path "/etc/sysconfig/beanstalkd" - owner "root" - group "root" - mode 0640 - variables( - :opts => node["beanstalkd"]["opts"] - ) - notifies :restart, "service[beanstalkd]" - end -end - -service "beanstalkd" do - start_command "/etc/init.d/beanstalkd start" - stop_command "/etc/init.d/beanstalkd stop" - status_command "/etc/init.d/beanstalkd status" - supports [:start, :stop, :status] - #starts the service if it's not running and enables it to start at system boot time - action [:enable, :start] -end +include_recipe "beanstalkd::repo" if node["beanstalkd"]["repo"] +include_recipe "beanstalkd::install" +include_recipe "beanstalkd::conf" +include_recipe "beanstalkd::service" diff --git a/recipes/install.rb b/recipes/install.rb new file mode 100644 index 0000000..de357ee --- /dev/null +++ b/recipes/install.rb @@ -0,0 +1 @@ +include_recipe "beanstalkd::install_#{node["beanstalk"]["install_method"]}" diff --git a/recipes/install_package.rb b/recipes/install_package.rb new file mode 100644 index 0000000..fa3177a --- /dev/null +++ b/recipes/install_package.rb @@ -0,0 +1,3 @@ +package "beanstalkd" do + action :upgrade if node["beanstalkd"]["upgrade"] +end diff --git a/recipes/repo.rb b/recipes/repo.rb new file mode 100644 index 0000000..38820cd --- /dev/null +++ b/recipes/repo.rb @@ -0,0 +1,10 @@ +case node["platform"] +when "ubuntu" + apt_repository "beanstalkd" do + uri "http://ppa.launchpad.net/jernej/beanstalkd/ubuntu" + distribution node['lsb']['codename'] + components ["main"] + keyserver "keyserver.ubuntu.com" + key "422D2977" + end +end diff --git a/recipes/service.rb b/recipes/service.rb new file mode 100644 index 0000000..b3bc638 --- /dev/null +++ b/recipes/service.rb @@ -0,0 +1,5 @@ +service "beanstalkd" do + supports :status => true + #starts the service if it's not running and enables it to start at system boot time + action [:enable, :start] +end