Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support of multiple node platforms.

Update of ssh check for CentOS
  • Loading branch information...
commit 093c68da1a27bf4c7adbac091b0be62b98d58c32 1 parent 9c0a3e4
Andriy SAMILYAK authored
View
15 attributes/default.rb
@@ -23,7 +23,7 @@
default["monit"]["alert_email"] = "root@localhost"
default["monit"]["web_interface"] = {
- :enable => true,
+ :enable => false,
:port => 2812,
:address => "localhost",
:allow => ["localhost", "admin:b1gbr0th3r"]
@@ -40,3 +40,16 @@
: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
+
+
+default["monit"]["configs"] = []
+
View
4 definitions/monitrc.rb
@@ -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
46 recipes/default.rb
@@ -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,44 @@
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|
+%w[ssh].each do |conf|
monitrc conf, :category => "system"
-end
+end
+
+node["monit"]["configs"].each do |conf|
+ monitrc conf, :category => "system"
+end
+
+
View
5 templates/centos/ssh.monitrc.erb
@@ -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
View
4 templates/default/monitrc.erb
@@ -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"] %>/*
Please sign in to comment.
Something went wrong with that request. Please try again.