bugfix: handle edge-cases in upstart service

e.g. when a service could not be found and command outputs become empty / matchers dont hit'
This commit is contained in:
Dominik Richter 2016-02-22 03:48:45 +01:00 committed by Stephan Renatus
parent f8c2b3fc1c
commit ee82c3a2ff

View file

@ -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