Skip to content

Commit

Permalink
bugfix: handle edge-cases in upstart service
Browse files Browse the repository at this point in the history
e.g. when a service could not be found and command outputs become empty / matchers dont hit'
  • Loading branch information
arlimus committed Feb 22, 2016
1 parent 15870af commit 752b084
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/resources/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ def info_enabled(status, service_name)
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
Expand All @@ -325,8 +327,10 @@ def info_enabled(status, service_name)
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

Expand Down

0 comments on commit 752b084

Please sign in to comment.