Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for multiple node platforms #1

Merged
merged 3 commits into from

3 participants

@werdan

Previously, cookbook worked correctly just for Debian/Ubuntu.
Added attributes for configuration of includes directory, main config file path.

Specifically updated ssh check for CentOS

Andriy SAMILYAK added some commits
Andriy SAMILYAK Support of multiple node platforms.
Update of ssh check for CentOS
093c68d
Andriy SAMILYAK Removing role-dependent monitrc checks 9208466
Andriy SAMILYAK Reverting web interface default enabled value
Reverting default list of checks
432a5b1
@phlipper
Owner

@werdan wow, thank you so much for this! This is a great addition!

@phlipper phlipper merged commit b1c104c into from
@dwradcliffe

What's the point of this if they are all the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 31, 2012
  1. Support of multiple node platforms.

    Andriy SAMILYAK authored
    Update of ssh check for CentOS
  2. Removing role-dependent monitrc checks

    Andriy SAMILYAK authored
  3. Reverting web interface default enabled value

    Andriy SAMILYAK authored
    Reverting default list of checks
This page is out of date. Refresh to see the latest.
View
9 attributes/default.rb
@@ -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
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
38 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,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
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"] %>/*
Something went wrong with that request. Please try again.