Method: Inspec::Resources::Postgres#initialize

Defined in:
lib/resources/postgres.rb

#initializePostgres

Returns a new instance of Postgres.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/resources/postgres.rb', line 12

def initialize
  if inspec.os.debian?
    #
    # https://wiki.debian.org/PostgreSql
    #
    # Debian allows multiple versions of postgresql to be
    # installed as well as multiple "clusters" to be configured.
    #
    @version = version_from_psql || version_from_dir('/etc/postgresql')
    @cluster = cluster_from_dir("/etc/postgresql/#{@version}")
    @conf_dir = "/etc/postgresql/#{@version}/#{@cluster}"
    @data_dir = "/var/lib/postgresql/#{@version}/#{@cluster}"
  else
    @version = version_from_psql
    if @version.nil?
      if inspec.directory('/var/lib/pgsql/data').exist?
        warn 'Unable to determine PostgreSQL version: psql did not return
         a version number and unversioned data directories were found.'
        nil
      else
        @version = version_from_dir('/var/lib/pgsql')
      end
    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