Class: Inspec::Resources::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/postgres.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/resources/postgres.rb', line 12

def initialize
  os = inspec.os
  if 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_dir('/etc/postgresql')
    cluster = cluster_from_dir("/etc/postgresql/#{version}")
    @conf_dir = "/etc/postgresql/#{version}/#{cluster}"
    @data_dir = "/var/lib/postgresql/#{version}/#{cluster}"
  elsif os.redhat?
    #
    # /var/lib/pgsql/data is the default data directory on RHEL6
    # and RHEL7. However, PR #824 explicitly added version-based
    # directories. Thus, we call #version_from_dir unless it looks
    # like we are using unversioned directories.
    #
    # TODO(ssd): This has the potential to be noisy because of the
    # warning in version_from_dir. We should determine which case
    # is more common and only warn in the less common case.
    #
    version = if inspec.directory('/var/lib/pgsql/data').exist?
                warn 'Found /var/lib/pgsql/data. Assuming postgresql install uses un-versioned directories.'
                nil
              else
                version_from_dir('/var/lib/pgsql/')
              end

    @data_dir = File.join('/var/lib/pgsql/', version.to_s, 'data')
  elsif os[:name] == 'arch'
    #
    # https://wiki.archlinux.org/index.php/PostgreSQL
    #
    # The archlinux wiki points to /var/lib/postgresql/data as the
    # main data directory.
    #
    @data_dir = '/var/lib/postgres/data'
  else
    #
    # According to https://www.postgresql.org/docs/9.5/static/creating-cluster.html
    #
    # > There is no default, although locations such as
    # > /usr/local/pgsql/data or /var/lib/pgsql/data are popular.
    #
    @data_dir = '/var/lib/pgsql/data'
  end

  @service = 'postgresql'
  @conf_dir ||= @data_dir
  verify_dirs
  @conf_path = File.join @conf_dir, 'postgresql.conf'
end

Instance Attribute Details

#conf_dirObject (readonly)

Returns the value of attribute conf_dir.



11
12
13
# File 'lib/resources/postgres.rb', line 11

def conf_dir
  @conf_dir
end

#conf_pathObject (readonly)

Returns the value of attribute conf_path.



11
12
13
# File 'lib/resources/postgres.rb', line 11

def conf_path
  @conf_path
end

#data_dirObject (readonly)

Returns the value of attribute data_dir.



11
12
13
# File 'lib/resources/postgres.rb', line 11

def data_dir
  @data_dir
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/resources/postgres.rb', line 11

def service
  @service
end

Instance Method Details

#to_sObject



68
69
70
# File 'lib/resources/postgres.rb', line 68

def to_s
  'PostgreSQL'
end