class Etoro::Utility::MCollective::Service
Public Instance Methods
check_run_status()
click to toggle source
# File lib/etoro/utility/mcollective/service.rb, line 43 def check_run_status @logger.info("Checking Service #{@config[:service_name]} for completion") begin timeout(@config[:timeout]) do until @service_status == {} @service_status.each do |host, status| run = rpcclient(self.class.name.downcase.split('::').last, :chomp => true) run.identity_filter host run.progress = false results = run.send 'status', service: @config[:service_name] results.each do |result| state = '' case @config[:action] when 'start' state = 'running' when 'stop' state = 'stopped' end @logger.info("#{host} - Service: current state: #{result[:data][:status]} desired_state: #{state}") if result[:data][:status] == state @logger.info("#{host} - Service: #{@config[:service_name]} #{@config[:action]} action #{result[:data][:status]} - completed") @service_status.delete(host) else @logger.info("#{host} - Service #{@config[:service_name]} #{@config[:action]} action not complete - #{result[:data][:status]}") end end end sleep @config[:wait_between_checks] end end rescue Timeout::Error @logger.error("Service run timed out. Took more than #{@config[:timeout]} seconds") exit 1 end end
execute()
click to toggle source
# File lib/etoro/utility/mcollective/service.rb, line 19 def execute @logger.info("Sending service #{@config[:service_name]} #{@config[:action]} action") @mc.send @config[:action], service: @config[:service_name] sleep @config[:wait_for_status] self.check_run_status end
hosts()
click to toggle source
# File lib/etoro/utility/mcollective/service.rb, line 35 def hosts hosts = [] @service_status.each_key do |host| @hosts.push host end hosts end
status()
click to toggle source
# File lib/etoro/utility/mcollective/service.rb, line 26 def status @service_status = {} @logger.info("Getting service information") results = @mc.send 'status', service: @config[:service_name] results.each do |result| @service_status[result[:sender]] = result[:data][:status] end end
validate(config)
click to toggle source
Calls superclass method
Etoro::Utility::MCollective::RPC#validate
# File lib/etoro/utility/mcollective/service.rb, line 6 def validate(config) super unless config.has_key?(:service_name) raise RuntimeError, "config[:service_name] must be defined" end unless config.has_key?(:action) raise RuntimeError, "config[:action] must be defined" end unless ['start','stop'].include? config[:action] raise RuntimeError, "Service action must be either start or stop" end end