Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

abstract a couple things out

  • Loading branch information...
commit 3c19ec15c99891bd6d894697c27bae635457a4d0 1 parent 0720893
@brianjlandau brianjlandau authored
Showing with 15 additions and 5 deletions.
  1. +8 −2 app/models/monit.rb
  2. +7 −3 app/models/site.rb
View
10 app/models/monit.rb
@@ -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
View
10 app/models/site.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.