Skip to content

Commit

Permalink
Merge pull request #3833 from chris-rock/chris-rock/postgres
Browse files Browse the repository at this point in the history
detect postgres 10 on centos properly
  • Loading branch information
clintoncwolfe committed Feb 27, 2019
2 parents 46a46dc + afadc89 commit c23d828
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions lib/resources/postgres.rb
Expand Up @@ -9,6 +9,28 @@ class Postgres < Inspec.resource(1)

attr_reader :service, :data_dir, :conf_dir, :conf_path, :version, :cluster
def initialize
# determine dirs and service based on versions
determine_dirs
determine_service

# print warnings if the dirs do not exist
verify_dirs

if !@version.nil? && !@conf_dir.empty?
@conf_path = File.join @conf_dir, 'postgresql.conf'
else
@conf_path = nil
return skip_resource 'Seems like PostgreSQL is not installed on your system'
end
end

def to_s
'PostgreSQL'
end

private

def determine_dirs
if inspec.os.debian?
#
# https://wiki.debian.org/PostgreSql
Expand All @@ -33,26 +55,18 @@ def initialize
end
@data_dir = locate_data_dir_location_by_version(@version)
end

@service = 'postgresql'
@service += "-#{@version}" if @version.to_f >= 9.4
@conf_dir ||= @data_dir

verify_dirs
if !@version.nil? && !@conf_dir.empty?
@conf_path = File.join @conf_dir, 'postgresql.conf'
else
@conf_path = nil
return skip_resource 'Seems like PostgreSQL is not installed on your system'
end
end

def to_s
'PostgreSQL'
def determine_service
@service = 'postgresql'
if @version.to_i >= 10
@service += "-#{@version.to_i}"
elsif @version.to_f >= 9.4
@service += "-#{@version}"
end
end

private

def verify_dirs
warn "Default postgresql configuration directory: #{@conf_dir} does not exist. " \
"Postgresql may not be installed or we've misidentified the configuration " \
Expand All @@ -71,6 +85,8 @@ def version_from_psql
def locate_data_dir_location_by_version(ver = @version)
dir_list = [
"/var/lib/pgsql/#{ver}/data",
# for 10, the versions are just stored in `10` although their version `10.7`
"/var/lib/pgsql/#{ver.to_i}/data",
'/var/lib/pgsql/data',
'/var/lib/postgres/data',
'/var/lib/postgresql/data',
Expand Down

0 comments on commit c23d828

Please sign in to comment.