Skip to content

Commit 0b83be5

Browse files
authored
Merge pull request #16 from atomic111/master
adjust the service for each os type and correct the control 10
2 parents 53f31ab + 06529b2 commit 0b83be5

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

controls/postgres_spec.rb

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,47 @@
6666
impact 1.0
6767
title 'Postgresql should be running'
6868
desc 'Postgresql should be running.'
69-
describe service(postgres.service) do
70-
it { should be_installed }
71-
it { should be_running }
72-
it { should be_enabled }
69+
# describe service(postgres.service) do
70+
# it { should be_installed }
71+
# it { should be_running }
72+
# it { should be_enabled }
73+
# end
74+
case os[:name]
75+
when 'ubuntu'
76+
case os[:release]
77+
when '12.04'
78+
describe command('/etc/init.d/postgresql status') do
79+
its('stdout') { should include 'online' }
80+
end
81+
when '14.04'
82+
describe command('service postgresql status') do
83+
its('stdout') { should include 'online' }
84+
end
85+
when '16.04'
86+
describe systemd_service(postgres.service) do
87+
it { should be_installed }
88+
it { should be_running }
89+
it { should be_enabled }
90+
end
91+
end
92+
when 'debian'
93+
case os[:release]
94+
when /7\./
95+
describe command('/etc/init.d/postgresql status') do
96+
its('stdout') { should include 'Running' }
97+
end
98+
end
99+
when 'redhat', 'centos', 'oracle', 'fedora'
100+
case os[:release]
101+
when /6\./
102+
describe command('/etc/init.d/postgresql-9.4 status') do
103+
its('stdout') { should include 'running' }
104+
end
105+
when /7\./
106+
describe command('ps aux | awk /\'bin\/postgres\'/ | wc -l') do
107+
its('stdout') { should include '1' }
108+
end
109+
end
73110
end
74111
end
75112

@@ -78,7 +115,7 @@
78115
title 'Use stable postgresql version'
79116
desc 'Use only community or commercially supported version of the PostgreSQL software. Do not use RC, DEVEL oder BETA versions in a production environment.'
80117
describe command('psql -V') do
81-
its('stdout') { should match(/9.[2-5]/) }
118+
its('stdout') { should match(/9.[1-5]/) }
82119
end
83120
describe command('psql -V') do
84121
its('stdout') { should_not match(/RC/) }
@@ -91,8 +128,10 @@
91128
impact 1.0
92129
title 'Run one postgresql instance per operating system'
93130
desc 'Only one postgresql database instance must be running on an operating system instance (both physical HW or virtualized).'
94-
describe command('ps aux | grep \'postgres -D\' | grep -v grep | wc -l') do
95-
its('stdout') { should match(/^1/) }
131+
pg_command = 'postgres'
132+
pg_command = 'postmaster' if os.redhat? && os.release.include?('6.')
133+
describe processes(pg_command) do
134+
its('list.length') { should eq 1 }
96135
end
97136
end
98137

@@ -162,14 +201,14 @@
162201
it { should be_directory }
163202
it { should be_owned_by USER }
164203
it { should be_readable.by('owner') }
165-
it { should be_readable.by('group') }
166-
it { should be_readable.by('other') }
204+
it { should_not be_readable.by('group') }
205+
it { should_not be_readable.by('other') }
167206
it { should be_writable.by('owner') }
168207
it { should_not be_writable.by('group') }
169208
it { should_not be_writable.by('other') }
170209
it { should be_executable.by('owner') }
171-
it { should be_executable.by('group') }
172-
it { should be_executable.by('other') }
210+
it { should_not be_executable.by('group') }
211+
it { should_not be_executable.by('other') }
173212
end
174213
describe file(POSTGRES_CONF_PATH) do
175214
it { should be_file }

0 commit comments

Comments
 (0)