mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Merge pull request #419 from chef/sr/fix-upstart-pre-1.3
upstart_service: fallback to config files if `show-config` is not available
This commit is contained in:
commit
5e1c9e24fa
6 changed files with 68 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
|
||||
|
|
|
@ -151,6 +151,8 @@ class MockLoader
|
|||
'initctl status ssh' => cmd.call('initctl-status-ssh'),
|
||||
# service config for upstart on ubuntu
|
||||
'initctl show-config ssh' => cmd.call('initctl-show-config-ssh'),
|
||||
# upstart version on ubuntu
|
||||
'initctl --version' => cmd.call('initctl--version'),
|
||||
# show ssh service Centos 7
|
||||
'systemctl show --all sshd' => cmd.call('systemctl-show-all-sshd'),
|
||||
'/path/to/systemctl show --all sshd' => cmd.call('systemctl-show-all-sshd'),
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
# author: Stephan Renatus
|
||||
|
||||
file "/etc/init/upstart-running.conf" do
|
||||
content "exec tail -f /dev/null"
|
||||
end
|
||||
|
||||
file "/etc/init/upstart-enabled-not-running.conf" do
|
||||
content "exec tail -f /dev/null\nstart on networking"
|
||||
end
|
||||
|
||||
file "/etc/init/upstart-enabled-and-running.conf" do
|
||||
content "exec tail -f /dev/null\nstart on networking"
|
||||
end
|
||||
|
||||
%w{ enabled-and-running running }.each do |srv|
|
||||
service "upstart-#{srv}" do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
action :start
|
||||
end
|
||||
end
|
|
@ -13,4 +13,5 @@ when 'ubuntu'
|
|||
when 'centos'
|
||||
# install runit for alternative service mgmt
|
||||
include_recipe 'os_prepare::_runit_service_centos'
|
||||
include_recipe 'os_prepare::_upstart_service_centos'
|
||||
end
|
||||
|
|
|
@ -78,4 +78,28 @@ if os[:family] == 'centos'
|
|||
it { should_not be_installed }
|
||||
it { should_not be_running }
|
||||
end
|
||||
|
||||
describe upstart_service('upstart-running') do
|
||||
it { should_not be_enabled }
|
||||
it { should be_installed }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
describe upstart_service('upstart-enabled-and-running') do
|
||||
it { should be_enabled }
|
||||
it { should be_installed }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
describe upstart_service('upstart-enabled-not-running') do
|
||||
it { should be_enabled }
|
||||
it { should be_installed }
|
||||
it { should_not be_running }
|
||||
end
|
||||
|
||||
describe upstart_service('unknown') do
|
||||
it { should_not be_enabled }
|
||||
it { should_not be_installed }
|
||||
it { should_not be_running }
|
||||
end
|
||||
end
|
||||
|
|
5
test/unit/mock/cmd/initctl--version
Normal file
5
test/unit/mock/cmd/initctl--version
Normal file
|
@ -0,0 +1,5 @@
|
|||
initctl (upstart 1.12.1)
|
||||
Copyright (C) 2006-2014 Canonical Ltd., 2011 Scott James Remnant
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE.
|
Loading…
Reference in a new issue