upstart_service: add version fallback, fix regexp

before this regexp change, a service called "running" (hello integration
tests) would always be "running" ;)
This commit is contained in:
Stephan Renatus 2016-02-05 09:25:34 +01:00 committed by Christoph Hartmann
parent eecb295377
commit f63a8ad1d5

View file

@ -227,7 +227,7 @@ class Upstart < ServiceManager
# @see: http://upstart.ubuntu.com/cookbook/#job-states
# grep for running to indicate the service is there
running = !status.stdout[/running/].nil?
running = !status.stdout[%r{start/running}].nil?
{
name: service_name,
@ -247,8 +247,15 @@ class Upstart < ServiceManager
# $ initctl show-config $job | grep -q "^ start on" && echo enabled || echo disabled
# Ubuntu 10.04 show-config is not supported
# @see http://manpages.ubuntu.com/manpages/maverick/man8/initctl.8.html
config = inspec.command("#{service_ctl} show-config #{service_name}")
enabled = !config.stdout[/^\s*start on/].nil?
support_for_show_config = Gem::Version.new('1.3')
if version >= support_for_show_config
config = inspec.command("#{service_ctl} show-config #{service_name}").stdout
else # use config file as fallback
config = inspec.file("/etc/init/#{service_name}.conf").content
end
enabled = !config[/^\s*start on/].nil?
# implement fallback for Ubuntu 10.04
if inspec.os[:family] == 'ubuntu' &&
@ -260,6 +267,11 @@ class Upstart < ServiceManager
enabled
end
def version
@version ||= Gem::Version.new(inspec.command("#{service_ctl} --version")
.stdout.match(/\(upstart ([^\)]+)\)/)[1])
end
end
class SysV < ServiceManager