Class: Escualo::Plugin::Postgres

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

Instance Method Summary collapse

Instance Method Details

#if_server(options) ⇒ Object



28
29
30
31
32
# File 'lib/escualo/plugin/postgres.rb', line 28

def if_server(options)
  unless options.pg_libs_only
    yield
  end
end

#installed?(session, options) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/escualo/plugin/postgres.rb', line 34

def installed?(session, options)
  session.check? 'psql --version', "psql (PostgreSQL) #{options.pg_version}"
end

#run(session, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/escualo/plugin/postgres.rb', line 3

def run(session, options)
  if_server options do
    raise 'missing pg-username' unless options.pg_username
    raise 'missing pg-password' unless options.pg_password
  end

  pg_hba_conf = "/etc/postgresql/#{options.pg_version}/main/pg_hba.conf"
  dependencies = options.pg_libs_only ?
      "postgresql-client-#{options.pg_version} libpq-dev" :
      "postgresql-#{options.pg_version} libpq-dev"

  Escualo::AptGet.install session, dependencies

  if_server options do
    session.tell_all! "echo 'local   all             postgres                                peer' > #{pg_hba_conf}",
                      "echo 'local   all             postgres                                peer' >> #{pg_hba_conf}",
                      "echo 'local   all             all                                     password' >> #{pg_hba_conf}",
                      "echo 'host    all             all             127.0.0.1/32            md5' >> #{pg_hba_conf}"

    session.tell_all! '/etc/init.d/postgresql restart',
                      'cd /',
                      "echo \"create role #{options.pg_username} with createdb login password '#{options.pg_password}';\" | sudo -u postgres PGDATABASE='' psql"
  end
end