Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
abstract a couple things out
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjlandau committed Oct 26, 2009
1 parent 0720893 commit 3c19ec1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/models/monit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ module Monit
extend self

def reload
system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
system format_command('reload')
end

def statuses
output = `monit summary `.scan(/Remote Host '.*_(\d+)'[ ]*(.*)$/)
output = `#{format_command('summary')}`.scan(/Remote Host '.*_(\d+)'[ ]*(.*)$/)

output.inject({}) do |coll, (site_id, status)|
coll[site_id.to_i] = (status == "online with all services" ? "success" : "fail")
coll
end
end

private

def format_command(command)
"#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} #{command}"
end
end
10 changes: 7 additions & 3 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ def monit_check_name

def create_monit_check
@template = MonitCheck.new(self)
File.open(root_path('monitrc', RACK_ENV, "#{self.id}.monitrc"), 'w') do |file|
File.open(monitrc_file, 'w') do |file|
file << @template.render
end

FileUtils.chmod 0700, root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
FileUtils.chmod 0700, monitrc_file
Monit.reload

return true
end

def delete_monit_check
FileUtils.rm_f root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
FileUtils.rm_f monitrc_file
Monit.reload

return true
end

def monitrc_file
root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
end
end

0 comments on commit 3c19ec1

Please sign in to comment.