Created
November 28, 2012 11:40
-
-
Save marceldegraaf/4160651 to your computer and use it in GitHub Desktop.
Chef monit cookbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default[:monit][:alert_emails] = %w( root@localhost ) | |
default[:monit][:logfile] = "/var/log/monit.log" | |
default[:monit][:alert_from] = "monit@localhost" | |
default[:monit][:remote_user] = 'admin' | |
default[:monit][:remote_password] = 'secret' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define :monitrc, rules: [], variables: {} do | |
Chef::Log.info("Generating monitrc for: #{params[:name]}") | |
template "/etc/monit/conf.d/#{params[:name]}.monitrc" do | |
mode "0744" | |
user "root" | |
source params[:source] | |
variables params[:variables] | |
notifies :restart, "service[monit]", :immediately | |
action :create | |
variables rules: params[:rules], | |
vars: params[:variables], | |
name: params[:name] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package "monit" | |
directory "/etc/monit/conf.d" do | |
action :create | |
recursive true | |
end | |
template "/etc/monit/monitrc" do | |
source "monitrc.erb" | |
mode "0600" | |
variables :alert_emails => node[:monit][:alert_emails], | |
:logfile => node[:monit][:logfile] | |
notifies :restart, "service[monit]" | |
end | |
service "monit" do | |
action :nothing | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set daemon 30 | |
set mailserver localhost | |
set mail-format { from: <%= node[:monit][:alert_from] %> } | |
<% @alert_emails.each do |email| -%> | |
set alert <%= email %> but not on { pid instance } | |
<% end %> | |
set eventqueue | |
basedir /var/monit | |
slots 100 | |
set logfile <%= @logfile %> | |
Include /etc/monit/conf.d/*.monitrc | |
set httpd port 2812 | |
allow <%= node[:monit][:remote_user] %>:<%= node[:monit][:remote_password] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an example of using the "monitrc" definition | |
monitrc :nginx do | |
source "nginx.monitrc.erb" # <= this is the monitrc.erb template in your own cookbook | |
rules node[:nginx][:monit][:rules] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process nginx | |
with pidfile <%= node[:nginx][:pid] %> | |
start program = "/etc/init.d/nginx start" as uid root and gid root | |
stop program = "/etc/init.d/nginx stop" as uid root and gid root | |
<% @rules.each do |rule| -%> | |
<%= rule %> | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment