Skip to content

Commit

Permalink
monit service style
Browse files Browse the repository at this point in the history
  • Loading branch information
lachie committed Oct 25, 2010
1 parent 4b508a4 commit fe4fc57
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
6 changes: 6 additions & 0 deletions targets/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def upstart_service
def redhat_service
include CommonMob::Services::Styles::Redhat
end
def monit_service
include CommonMob::Services::Styles::Monit
end
end

default_action
Expand Down Expand Up @@ -86,6 +89,9 @@ def self.at_least_lucid?
issue = "/etc/issue".pathname
issue.exist? && issue.read[/ubuntu.+10\.04/i]
end
def at_least_lucid?
self.class.at_least_lucid?
end


protected
Expand Down
71 changes: 71 additions & 0 deletions targets/services/styles/monit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'fileutils'
require 'common_mob'

module CommonMob
module Services
module Styles
module Monit
include CommonMob::ShellHelper

def enable_service
return if service_enabled?

FileUtils.mv( disabled_monit_config, monit_config ) if disabled_monit_config.exist?

raise "unable to enable monit config" unless monit_config.tapp(:mc).exist?

reload_monit!
end

def service_enabled?
end

def remove_service
FileUtils.mv( monit_config, disabled_monit_config ) if monit_config.exist?
reload_monit!
end

def signal_service(signal,should_raise=false)
begin
monit(signal, name).run
rescue CommonMob::ShellError
if should_raise
raise $!
else
log "monit #{signal} #{name} failed (but swallowing exception)"
log "(out=#{$!.result.stdout})"
log "(err=#{$!.result.stderr})"
end
end
end

def is_running?
end

def ensure_running!
unless is_running?
raise "#{name} should be running but isn't"
end
log "#{name} is running"
end

protected
def monit(cmd,*args)
sh("/usr/local/bin/monit #{cmd} #{args * ' '}")
end

def reload_monit!
monit('reload').run
end

def monit_config
Pathname("/etc/monit.d/#{name}.rc")
end

def disabled_monit_config
Pathname("/etc/monit.d/#{name}.rc.am-disabled")
end
end
end
end
end
2 changes: 1 addition & 1 deletion targets/services/styles/upstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def enable_service

FileUtils.mv( disabled_upstart_config, upstart_config ) if disabled_upstart_config.exist?

raise "unable to enable config" unless upstart_config.exist?
raise "unable to enable upstart config" unless upstart_config.exist?
end

def service_enabled?
Expand Down

0 comments on commit fe4fc57

Please sign in to comment.