-
Notifications
You must be signed in to change notification settings - Fork 18
/
monit.rb
37 lines (33 loc) · 1023 Bytes
/
monit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace :monit do
desc "Install Monit"
task :install do
run "#{sudo} apt-get -y install monit"
end
after "deploy:install", "monit:install"
desc "Setup all Monit configuration"
task :setup do
monit_config "monitrc", "/etc/monit/monitrc"
nginx
postgresql
unicorn
syntax
reload
end
after "deploy:setup", "monit:setup"
task(:nginx, roles: :web) { monit_config "nginx" }
task(:postgresql, roles: :db) { monit_config "postgresql" }
task(:unicorn, roles: :app) { monit_config "unicorn" }
%w[start stop restart syntax reload].each do |command|
desc "Run Monit #{command} script"
task command do
run "#{sudo} service monit #{command}"
end
end
end
def monit_config(name, destination = nil)
destination ||= "/etc/monit/conf.d/#{name}_#{application}.conf"
template "monit/#{name}.erb", "/tmp/monit_#{name}"
run "#{sudo} mv /tmp/monit_#{name} #{destination}"
run "#{sudo} chown root #{destination}"
run "#{sudo} chmod 600 #{destination}"
end