From ee82c3a2ff006a6df16bf1f4185ecd47eebc9896 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Mon, 22 Feb 2016 03:48:45 +0100 Subject: [PATCH] bugfix: handle edge-cases in upstart service e.g. when a service could not be found and command outputs become empty / matchers dont hit' --- lib/resources/service.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 6baa0e584..b77174946 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -311,6 +311,8 @@ class Upstart < ServiceManager config = inspec.file("/etc/init/#{service_name}.conf").content end + # disregard if the config does not exist + return nil if config.nil? enabled = !config[/^\s*start on/].nil? # implement fallback for Ubuntu 10.04 @@ -325,8 +327,10 @@ class Upstart < ServiceManager end def version - @version ||= Gem::Version.new(inspec.command("#{service_ctl} --version") - .stdout.match(/\(upstart ([^\)]+)\)/)[1]) + @version ||= ( + out = inspec.command("#{service_ctl} --version").stdout + Gem::Version.new(out[/\(upstart ([^\)]+)\)/, 1]) + ) end end