From ed831137ffbd05ed9b2044a93e7432e86c5529b3 Mon Sep 17 00:00:00 2001 From: Robby Grossman Date: Wed, 4 Jul 2012 14:11:34 -0400 Subject: [PATCH] Add more flexibility to the monitrc definition by allowing monit configs to be impelemented in third-party cookbooks. --- definitions/monitrc.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/definitions/monitrc.rb b/definitions/monitrc.rb index 711a8fe..85d9a18 100644 --- a/definitions/monitrc.rb +++ b/definitions/monitrc.rb @@ -1,13 +1,17 @@ # reload: Reload monit so it notices the new service. :delayed (default) or :immediately. # action: :enable To create the monitoring config (default), or :disable to remove it. -define :monitrc, :action => :enable, :reload => :delayed, :variables => {} do +# variables: Hash of instance variables to pass to the ERB template +# template_cookbook: the cookbook in which the configuration resides +# template_source: filename of the ERB configuration template, defaults to .conf.erb +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 owner "root" group "root" mode 0644 - source "#{params[:name]}.conf.erb" - cookbook "monit" + source params[:template_source] + cookbook params[:template_cookbook] variables params[:variables] notifies :restart, resources(:service => "monit"), params[:reload] action :create