Skip to content

adjust the service for each os type and correct the control 10 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions controls/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,37 @@
impact 1.0
title 'Postgresql should be running'
desc 'Postgresql should be running.'
describe service(postgres.service) do
it { should be_installed }
it { should be_running }
it { should be_enabled }
case os[:name]
when 'ubuntu'
case os[:release]
when '12.04'
describe service(postgres.service) do
it { should be_installed }
it { should be_running }
it { should be_enabled }
end
when '16.04'
describe systemd_service(postgres.service) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be related to inspec/inspec#931, similar things are reported to happen with debian

it { should be_installed }
it { should be_running }
it { should be_enabled }
end
end
when 'redhat', 'centos', 'oracle'
case os[:release]
when /6\./
describe runit_service(postgres.service) do
it { should be_installed }
it { should be_running }
it { should be_enabled }
end
when /7\./
describe systemd_service(postgres.service) do
it { should be_installed }
it { should be_running }
it { should be_enabled }
end
end
end
end

Expand All @@ -91,8 +118,14 @@
impact 1.0
title 'Run one postgresql instance per operating system'
desc 'Only one postgresql database instance must be running on an operating system instance (both physical HW or virtualized).'
describe command('ps aux | grep \'postgres -D\' | grep -v grep | wc -l') do
its('stdout') { should match(/^1/) }
if os[:family] == 'debian'
describe processes('postgres') do
its('list.length') { should eq 1 }
end
elsif os[:family] == 'redhat'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use os.redhat? and os.debian?

describe processes('postmaster') do
its('list.length') { should eq 1 }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe:

if os.redhat? && os.release.include?('6')
  pg_command = 'postmaster'
else
  pg_command = 'postgres'
end

describe processes('postmaster') do
   its('list.length') { should eq 1 }
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the input. i will do the changes

end
end

Expand Down Expand Up @@ -162,14 +195,14 @@
it { should be_directory }
it { should be_owned_by USER }
it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_readable.by('other') }
it { should_not be_readable.by('group') }
it { should_not be_readable.by('other') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('group') }
it { should_not be_writable.by('other') }
it { should be_executable.by('owner') }
it { should be_executable.by('group') }
it { should be_executable.by('other') }
it { should_not be_executable.by('group') }
it { should_not be_executable.by('other') }
end
describe file(POSTGRES_CONF_PATH) do
it { should be_file }
Expand Down