Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # deploy.rb
- # This requires that you create in your shared directory config/database.yml
- after "deploy:update_code", "link_files"
- namespace :link_files do
- task :default do
- database_config
- end
- desc "Link the server's database.yml file for rails."
- task :database_config, :roles => [:app] do
- run "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
- end
- end
- desc "Creates the database.yml for the server."
- task :create_db_yml, :roles => [:app] do
- puts "I need some info to create the database.yml file for the #{application} app:"
- db_cfg = {}
- passwd = ""
- c_passwd = ""
- begin
- puts "Dreamshots Database:"
- db_cfg[:user] = Capistrano::CLI.ui.ask("Username: ") {|q| q.default = 'ruby'}
- begin
- passwd = Capistrano::CLI.password_prompt "Password: "
- c_passwd = Capistrano::CLI.password_prompt "Confirm Password: "
- puts "Passwords do not match" if passwd != c_passwd
- end while passwd != c_passwd
- db_cfg[:pw] = passwd
- db_cfg[:host] = Capistrano::CLI.ui.ask("Host name: ") {|q| q.default = 'localhost'}
- db_cfg[:socket] = Capistrano::CLI.ui.ask("Socket: ") {|q| q.default = '/var/lib/mysql/mysql.sock'}
- db_cfg[:production_name] = Capistrano::CLI.ui.ask("Production database name: ") {|q| q.default = application}
- db_cfg[:test_name] = Capistrano::CLI.ui.ask("Test database name: ") {|q| q.default = "#{application}_test"}
- db_cfg[:development_name] = Capistrano::CLI.ui.ask("Development database name: ") {|q| q.default = "#{application}_dev"}
- puts "Database Configuration:"
- puts "Database User:".ljust(30) + db_cfg[:user]
- puts "Database Password:".ljust(30) + "******"
- puts "Database Host:".ljust(30) + db_cfg[:host]
- puts "Database Socket:".ljust(30) + db_cfg[:socket]
- puts "Database Production:".ljust(30) + db_cfg[:production_name]
- puts "Database Test:".ljust(30) + db_cfg[:test_name]
- puts "Database Development:".ljust(30) + db_cfg[:development_name]
- end until Capistrano::CLI.ui.agree "Is this accurate (y/n)? "
- db_config = ERB.new <<-EOF
- base: &base
- adapter: mysql
- socket: #{db_cfg[:socket]}
- username: #{db_cfg[:user]}
- password: #{db_cfg[:pw]}
- host: localhost
- development:
- database: #{db_cfg[:development_name]}
- <<: *base
- test:
- database: #{db_cfg[:test_name]}
- <<: *base
- production:
- database: #{db_cfg[:production_name]}
- <<: *base
- EOF
- put db_config.result, "#{shared_path}/config/database.yml"
- run "chgrp #{group} #{shared_path}/config/database.yml"
- run "chmod 660 #{shared_path}/config/database.yml"
- end
Add Comment
Please, Sign In to add comment