From 4294aa4e0e5e986afe3718eccd8373952fc12e58 Mon Sep 17 00:00:00 2001 From: Vladimir Malyarevich Date: Wed, 4 Feb 2015 14:44:40 -0800 Subject: [PATCH] Fix for #63 issue. Added support for different platforms Tests are also updated. --- Gemfile.lock | 2 +- definitions/monitrc.rb | 4 ++-- metadata.rb | 2 +- recipes/default.rb | 13 +++++++++++-- spec/unit/recipes/default_spec.rb | 6 ++++-- spec/unit/recipes/postfix_spec.rb | 2 +- spec/unit/recipes/postgres_spec.rb | 2 +- spec/unit/recipes/resque_scheduler_spec.rb | 2 +- spec/unit/recipes/resque_spec.rb | 2 +- spec/unit/recipes/unicorn_spec.rb | 2 +- 10 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 63467d1..bbee224 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,7 @@ GEM puma (1.6.3) rack (~> 1.2) rack (1.5.2) - rake (10.3.2) + rake (10.4.2) rest-client (1.6.7) mime-types (>= 1.16) rspec (2.99.0) diff --git a/definitions/monitrc.rb b/definitions/monitrc.rb index 304596a..bce6e7f 100644 --- a/definitions/monitrc.rb +++ b/definitions/monitrc.rb @@ -6,7 +6,7 @@ define :monitrc, :action => :enable, :reload => :delayed, :variables => {}, :template_cookbook => "monit", :template_source => nil do params[:template_source] ||= "#{params[:name]}.conf.erb" if params[:action] == :enable - template "/etc/monit/conf.d/#{params[:name]}.conf" do + template File.join(node['monit']['conf_dir'], "#{params[:name]}.conf") do owner "root" group "root" mode 0644 @@ -17,7 +17,7 @@ action :create end else - file "/etc/monit/conf.d/#{params[:name]}.conf" do + file File.join(node['monit']['conf_dir'], "#{params[:name]}.conf") do action :delete notifies :restart, "service[monit]", params[:reload] end diff --git a/metadata.rb b/metadata.rb index 24e42fa..082085c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license "MIT" description "Configures monit. Originally based off the 37 Signals Cookbook." long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.7.5" +version "0.7.6" attribute 'monit/notify_email', diff --git a/recipes/default.rb b/recipes/default.rb index 08f78d9..7b0b953 100755 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -8,8 +8,17 @@ only_if { platform?("ubuntu") || platform?("debian") } end +case node['platform'] +when 'ubuntu', 'debian' + node.default['monit']['conf_file'] = '/etc/monit/monitrc' + node.default['monit']['conf_dir'] = '/etc/monit/conf.d/' -directory "/etc/monit/conf.d/" do +when 'redhat', 'fedora', 'centos' # ~FC024 + node.default['monit']['conf_file'] = '/etc/monit.conf' + node.default['monit']['conf_dir'] = '/etc/monit.d/' +end + +directory node['monit']['conf_dir'] do owner 'root' group 'root' mode 0755 @@ -17,7 +26,7 @@ recursive true end -template "/etc/monit/monitrc" do +template node['monit']['conf_file'] do owner "root" group "root" mode 0700 diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index ae82167..4117cd1 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -2,7 +2,9 @@ describe 'monit::default' do context "with default attributes" do - let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } + let(:chef_run) do + runner = ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04').converge(described_recipe) + end it 'creates /etc/monit/conf.d/' do expect(chef_run).to create_directory('/etc/monit/conf.d/').with(user: 'root', group: 'root', mode: 0755) @@ -36,7 +38,7 @@ context "with configuration" do let(:chef_run) do - runner = ChefSpec::Runner.new do |node| + runner = ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04') do |node| node.set[:monit][:notify_email] = 'johndoe@example.com' node.set[:monit][:logfile] = '/var/log/monit.log' node.set[:monit][:poll_period] = 30 diff --git a/spec/unit/recipes/postfix_spec.rb b/spec/unit/recipes/postfix_spec.rb index c430f8b..b7a22f6 100644 --- a/spec/unit/recipes/postfix_spec.rb +++ b/spec/unit/recipes/postfix_spec.rb @@ -2,7 +2,7 @@ describe 'monit::postfix' do let(:chef_run) do - runner = ChefSpec::Runner.new.converge(described_recipe) + runner = ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04').converge(described_recipe) end # Temporary soultion for testing definitions/monitrc.erb without monky patch. diff --git a/spec/unit/recipes/postgres_spec.rb b/spec/unit/recipes/postgres_spec.rb index b065b81..e4bd158 100644 --- a/spec/unit/recipes/postgres_spec.rb +++ b/spec/unit/recipes/postgres_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'monit::postgresql' do - let(:chef_run) { ChefSpec::Runner.new.converge described_recipe } + let(:chef_run) { ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04').converge described_recipe } it 'creates /etc/monit/conf.d/postgresql.conf' do expect(chef_run).to create_template('/etc/monit/conf.d/postgresql.conf').with(user: 'root', group: 'root', mode: 0644) diff --git a/spec/unit/recipes/resque_scheduler_spec.rb b/spec/unit/recipes/resque_scheduler_spec.rb index c0251fe..b5e2cda 100644 --- a/spec/unit/recipes/resque_scheduler_spec.rb +++ b/spec/unit/recipes/resque_scheduler_spec.rb @@ -2,7 +2,7 @@ describe 'monit::resque_scheduler' do let(:chef_run) do - ChefSpec::Runner.new do |node| + ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04') do |node| node.set[:monit][:resque][:app_root] = '/www/myapp-test/current' end.converge(described_recipe) end diff --git a/spec/unit/recipes/resque_spec.rb b/spec/unit/recipes/resque_spec.rb index 5202f5a..aeb1ac5 100644 --- a/spec/unit/recipes/resque_spec.rb +++ b/spec/unit/recipes/resque_spec.rb @@ -2,7 +2,7 @@ describe 'monit::resque' do def chef_run(monit_resque_attrs = {}) - @chef_run ||= ChefSpec::Runner.new do |node| + @chef_run ||= ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04') do |node| node.set[:monit][:resque] = monit_resque_attrs end.converge described_recipe end diff --git a/spec/unit/recipes/unicorn_spec.rb b/spec/unit/recipes/unicorn_spec.rb index 57db84b..350c17f 100644 --- a/spec/unit/recipes/unicorn_spec.rb +++ b/spec/unit/recipes/unicorn_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'monit::unicorn' do - let(:chef_run) { ChefSpec::Runner.new.converge described_recipe } + let(:chef_run) { ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04').converge described_recipe } it 'creates /etc/monit/conf.d/unicorn.conf' do expect(chef_run).to create_template('/etc/monit/conf.d/unicorn.conf').with(user: 'root', group: 'root', mode: 0644)