mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
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:
parent
eecb295377
commit
f63a8ad1d5
1 changed files with 15 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue