diff options
| author | Tyler Mercier <tylermercier@gmail.com> | 2013-07-22 16:51:00 -0600 |
|---|---|---|
| committer | Tyler Mercier <tylermercier@gmail.com> | 2013-07-22 16:51:00 -0600 |
| commit | a78d9585c7b7c3255d7e96a110daae21b073eeb0 (patch) | |
| tree | 645fa5e0c8c8c9017f8dc65dd55d756ee5831bab /config/recipes/postgresql.rb | |
| parent | c306fa8b20ff7c24f26e657d7ac3a7e42dbe20de (diff) | |
add recipes for install
Diffstat (limited to 'config/recipes/postgresql.rb')
| -rw-r--r-- | config/recipes/postgresql.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/config/recipes/postgresql.rb b/config/recipes/postgresql.rb new file mode 100644 index 0000000..19d9863 --- /dev/null +++ b/config/recipes/postgresql.rb @@ -0,0 +1,34 @@ +set_default(:postgresql_host, "localhost") +set_default(:postgresql_user) { application } +set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " } +set_default(:postgresql_database) { "#{application}_production" } + +namespace :postgresql do + desc "Install the latest stable release of PostgreSQL." + task :install, roles: :db, only: {primary: true} do + run "#{sudo} add-apt-repository ppa:pitti/postgresql" + run "#{sudo} apt-get -y update" + run "#{sudo} apt-get -y install postgresql libpq-dev" + end + after "deploy:install", "postgresql:install" + + desc "Create a database for this application." + task :create_database, roles: :db, only: {primary: true} do + run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"} + run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"} + end + after "deploy:setup", "postgresql:create_database" + + desc "Generate the database.yml configuration file." + task :setup, roles: :app do + run "mkdir -p #{shared_path}/config" + template "postgresql.yml.erb", "#{shared_path}/config/database.yml" + end + after "deploy:setup", "postgresql:setup" + + desc "Symlink the database.yml file into latest release" + task :symlink, roles: :app do + run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" + end + after "deploy:finalize_update", "postgresql:symlink" +end |
