Skip to content

Commit

Permalink
Support of multiple node platforms.
Browse files Browse the repository at this point in the history
Update of ssh check for CentOS
  • Loading branch information
Andriy SAMILYAK committed Oct 31, 2012
1 parent 9c0a3e4 commit 093c68d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
15 changes: 14 additions & 1 deletion attributes/default.rb
Expand Up @@ -23,7 +23,7 @@
default["monit"]["alert_email"] = "root@localhost" default["monit"]["alert_email"] = "root@localhost"


default["monit"]["web_interface"] = { default["monit"]["web_interface"] = {
:enable => true, :enable => false,
:port => 2812, :port => 2812,
:address => "localhost", :address => "localhost",
:allow => ["localhost", "admin:b1gbr0th3r"] :allow => ["localhost", "admin:b1gbr0th3r"]
Expand All @@ -40,3 +40,16 @@
:tls => false, :tls => false,
:timeout => 30 :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"] = []

4 changes: 2 additions & 2 deletions definitions/monitrc.rb
@@ -1,13 +1,13 @@
define :monitrc, :name => nil, :variables => {} do define :monitrc, :name => nil, :variables => {} do
Chef::Log.info("Making monitrc for: #{params[:name]}") 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" owner "root"
group "root" group "root"
mode "0644" mode "0644"
source "#{params[:name]}.monitrc.erb" source "#{params[:name]}.monitrc.erb"
variables params[:variables] variables params[:variables]
notifies :run, resources(:execute => "restart-monit") notifies :restart, resources(:service => "monit")
action :create action :create
end end
end end
46 changes: 36 additions & 10 deletions recipes/default.rb
Expand Up @@ -2,7 +2,7 @@
action :install action :install
end end


template "/etc/monit/monitrc" do template "#{node["monit"]["main_config_path"]}" do
owner "root" owner "root"
group "root" group "root"
mode "0700" mode "0700"
Expand All @@ -15,18 +15,44 @@
mode "0700" mode "0700"
end end


# enable startup service "monit" do
execute "enable-monit-startup" do service_name "monit"
command "/bin/sed s/startup=0/startup=1/ -i /etc/default/monit" case node['platform']
not_if "grep 'startup=1' /etc/default/monit" 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 end


execute "restart-monit" do case node['platform']
command "/usr/sbin/service monit restart" when "debian", "ubuntu"
action :nothing # 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 end


# build monitrc files # build monitrc files
%w[load ssh].each do |conf| %w[ssh].each do |conf|
monitrc conf, :category => "system" monitrc conf, :category => "system"
end end

node["monit"]["configs"].each do |conf|
monitrc conf, :category => "system"
end


5 changes: 5 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions templates/default/monitrc.erb
Expand Up @@ -28,8 +28,8 @@ set mail-format {
message: <%= node[:monit][:mail][:message] %> message: <%= node[:monit][:mail][:message] %>
} }


# Web interface
<% if node[:monit][:web_interface][:enable] %> <% if node[:monit][:web_interface][:enable] %>
# Web interface
set httpd port <%= node[:monit][:web_interface][:port] %> and set httpd port <%= node[:monit][:web_interface][:port] %> and
use address <%= node[:monit][:web_interface][:address] %> use address <%= node[:monit][:web_interface][:address] %>
<% node[:monit][:web_interface][:allow].each do |allow| -%> <% node[:monit][:web_interface][:allow].each do |allow| -%>
Expand All @@ -38,4 +38,4 @@ set httpd port <%= node[:monit][:web_interface][:port] %> and
<% end %> <% end %>


# Include config files # Include config files
include /etc/monit/conf.d/* include <%= node["monit"]["includes_dir"] %>/*

0 comments on commit 093c68d

Please sign in to comment.