Sha256: 6033d9bf22640a433c3c7cf67144596ae83b4c7d6d57fa118405e8d37e5c906e

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

puts "?? Installed version of psql is #{`psql --version`=~/\s(\d.\d)\./;$1}"

if tagged?("ubuntu | debian")
  etc_postgresql = "/etc/postgresql/#{$1}/main/"

elsif tagged?("fedora | centos")
  etc_postgresql = "/var/lib/pgsql/#{$1}/data/"

end

puts etc_postgresql
#service_manager.stop("postgresql")

locals = {
    :port   => lookup('database#port'),
    :max_connections   => lookup('database#max_connections')
}
render  :file => "#{dist}postgresql/postgresql.conf.erb",
        :to => "#{etc_postgresql}postgresql.conf",
        :user => 'postgres',
        :group => 'rmails',
        :locals => locals

edit(:file => "#{etc_postgresql}pg_hba.conf") do
  unless contains?(/^host\sall\sall\s127.0.0.1\/32\smd5$/)
    append("host \t all \t all \t 127.0.0.1/32 \t md5")
  end
end

service_manager.restart("postgresql")

# get password for database connection
password = lookup('postfix#database#password')

if 1 ==`sudo -u postgres psql -l | grep -w rmails | wc -l`
# create roles and application database
  shell_manager.sh "sudo -u postgres psql << EOF
    CREATE USER postfix ENCRYPTED password '#{password}';
    CREATE USER dovecot ENCRYPTED password '#{password}';
    CREATE ROLE rmails_app WITH USER postfix, dovecot LOGIN PASSWORD '#{password}';
    CREATE DATABASE rmails OWNER rmails_app;
  EOF", :quiet => true
end

# render rails database definition
locals = {
    :password => password,
    :dbhost   => lookup('database#host'),
    :dbport   => lookup('database#port')
}
render  :file => "#{dist}rmails/database.yml.erb",
        :to => "#{rails_root}/config/database.yml",
        :locals => locals

# create database schema via ActiveRecord Migrations
#rake_task["db:migrate"].reenable
#rake_task["db:migrate"].invoke
shell_manager.sh "rake db:setup"

# grant privileges for postfix and dovecot roles
shell_manager.sh "sudo -u postgres psql -d rmails << EOF
  GRANT SELECT ON virtual_aliases TO dovecot;
  GRANT SELECT ON virtual_domains,virtual_users,virtual_aliases TO postfix;
EOF"

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rmails-0.2.0 system/recipes/02_setup_database.rb
rmails-0.1.6 system/recipes/02_setup_database.rb
rmails-0.1.5 system/recipes/02_setup_database.rb
rmails-0.1.4 system/recipes/02_setup_database.rb
rmails-0.1.3 system/recipes/02_setup_database.rb
rmails-0.1.2 system/recipes/02_setup_database.rb
rmails-0.1.1 system/recipes/02_setup_database.rb