Module: Mimas::Plugins::Server::PostgreSQL

Defined in:
lib/mimas/plugins/server/postgresql.rb

Instance Method Summary collapse

Instance Method Details

#configure_postgresql(sudo_user:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mimas/plugins/server/postgresql.rb', line 11

def configure_postgresql(sudo_user:)
  ssh(self, user: sudo_user) do |session|
    config_file_path = session.run "sudo -u postgres psql -AtXc 'SHOW config_file'", capture: true
    config_dir = Pathname.new(config_file_path.strip).parent

    config_files = find_files("postgresql/**/*.conf")
    config_files = config_files.map do |path|
      [ path, path.split("/postgresql/")[1] ]
    end.to_h

    tmp_dir = Pathname.new("/").join("tmp", "postgresql")

    config_files.each do |file, destination|
      destination_parent_folder = Pathname.new(destination).parent

      session.run "mkdir -p #{tmp_dir.join(destination_parent_folder)}"
      session.upload file, tmp_dir.join(destination)
    end

    session.run "sudo rsync --archive --recursive --chown=postgres:postgres #{tmp_dir.join("*")} #{config_dir}"
    session.run "rm -rf #{tmp_dir}"
    session.run "sudo systemctl restart postgresql"
  end
end

#install_postgresql(sudo_user:) ⇒ Object



5
6
7
8
9
# File 'lib/mimas/plugins/server/postgresql.rb', line 5

def install_postgresql(sudo_user:)
  ssh(self, user: sudo_user) do |session|
    session.run "sudo apt-get install postgresql postgresql-contrib -y"
  end
end