Support for multiple node platforms #1

Merged
merged 3 commits into from Oct 31, 2012
View
@@ -40,3 +40,12 @@
:tls => false,
:timeout => 30
}
+
+case platform
+when "redhat","centos","fedora"
+ default["monit"]["main_config_path"] = "/etc/monit.conf"
+ default["monit"]["includes_dir"] = "/etc/monit.d"
+else
+ default["monit"]["main_config_path"] = "/etc/monit/monitrc"
+ default["monit"]["includes_dir"] = "/etc/monit/conf.d"
+end
View
@@ -1,13 +1,13 @@
define :monitrc, :name => nil, :variables => {} do
Chef::Log.info("Making monitrc for: #{params[:name]}")
- template "/etc/monit/conf.d/#{params[:name]}.monitrc" do
+ template "#{node["monit"]["includes_dir"]}/#{params[:name]}.monitrc" do
owner "root"
group "root"
mode "0644"
source "#{params[:name]}.monitrc.erb"
variables params[:variables]
- notifies :run, resources(:execute => "restart-monit")
+ notifies :restart, resources(:service => "monit")
action :create
end
end
View
@@ -2,7 +2,7 @@
action :install
end
-template "/etc/monit/monitrc" do
+template "#{node["monit"]["main_config_path"]}" do
owner "root"
group "root"
mode "0700"
@@ -15,18 +15,38 @@
mode "0700"
end
-# enable startup
-execute "enable-monit-startup" do
- command "/bin/sed s/startup=0/startup=1/ -i /etc/default/monit"
- not_if "grep 'startup=1' /etc/default/monit"
+service "monit" do
+ service_name "monit"
+ case node['platform']
+ when "redhat","centos","scientific","fedora","suse","amazon"
+ start_command "/sbin/service monit start"
+ restart_command "/sbin/service monit restart"
+ when "debian","ubuntu"
+ start_command "/usr/sbin/invoke-rc.d monit start"
+ restart_command "/usr/sbin/invoke-rc.d monit restart"
+ end
+ supports value_for_platform(
+ "debian" => { "4.0" => [ :restart, :start ], "default" => [ :restart, :start ] },
+ "ubuntu" => { "default" => [ :restart, :start ] },
+ "redhat" => { "default" => [ :restart, :start ] },
+ "centos" => { "default" => [ :restart, :start ] },
+ "fedora" => { "default" => [ :restart, :start ] },
+ "default" => { "default" => [:restart, :start ] }
+ )
+ action :enable
end
-execute "restart-monit" do
- command "/usr/sbin/service monit restart"
- action :nothing
+case node['platform']
+when "debian", "ubuntu"
+ # enable startup
+ execute "enable-monit-startup" do
+ command "/bin/sed s/startup=0/startup=1/ -i /etc/default/monit"
+ not_if "grep 'startup=1' /etc/default/monit"
+ end
+else
end
# build monitrc files
%w[load ssh].each do |conf|
monitrc conf, :category => "system"
-end
+end
@@ -0,0 +1,5 @@
+check process sshd with pidfile /var/run/sshd.pid
+ start program "/sbin/service sshd start"
+ stop program "/sbin/service sshd stop"
+ if failed port 22 protocol ssh then restart
+ if 5 restarts within 5 cycles then timeout
@@ -28,8 +28,8 @@ set mail-format {
message: <%= node[:monit][:mail][:message] %>
}
-# Web interface
<% if node[:monit][:web_interface][:enable] %>
+# Web interface
set httpd port <%= node[:monit][:web_interface][:port] %> and
use address <%= node[:monit][:web_interface][:address] %>
<% node[:monit][:web_interface][:allow].each do |allow| -%>
@@ -38,4 +38,4 @@ set httpd port <%= node[:monit][:web_interface][:port] %> and
<% end %>
# Include config files
-include /etc/monit/conf.d/*
+include <%= node["monit"]["includes_dir"] %>/*