Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set :application, "application"
- set :user, 'deploy'
- set :group, 'admin'
- set :server_name, "adamelliot.com"
- set :server_alias, "*.adamelliot.*"
- set :git_server, "git.warptube.com"
- ssh_options[:port] = 22
- # You shouldn't need to change anything past this point, unless you are
- # modifying the script for a different server configuration.
- set :scm_user, "cap"
- set :repository, "git@#{git_server}:#{application}.git"
- set :scm, "git"
- set :checkout, "export"
- set :deploy_via, :remote_cache
- set :branch, "master"
- set :base_path, "/u/apps"
- set :deploy_to, "#{base_path}/#{application}"
- set :apache_site_folder, "/etc/apache2/sites-enabled"
- set :use_sudo, true
- set :keep_releases, 3
- role :app, server_name
- role :web, server_name
- role :db, server_name, :primary => true
- ssh_options[:paranoid] = false
- default_run_options[:pty] = true
- after "deploy:setup", "init:set_permissions"
- after "deploy:setup", "init:database_yml"
- after "deploy:setup", "init:create_database"
- after "deploy:setup", "init:create_vhost"
- after "deploy:setup", "init:enable_site"
- after "deploy:setup", "config:reload_apache"
- after "deploy", "deploy:restart"
- #after "deploy", "sphinx:index"
- after "deploy:update_code", "config:copy_shared_configurations"
- namespace :deploy do
- [:start, :restart].each do |t|
- desc "Restarting mod_rails with restart.txt"
- task t, :roles => :app, :except => {:no_release => true} do
- run "touch #{current_path}/tmp/restart.txt"
- end
- end
- desc "Runs db:populate on the server."
- task :migrate_and_populate do
- run("cd #{current_path}; /usr/bin/rake db:populate RAILS_ENV=production")
- end
- desc "Stop task is a no-op with mod_rails"
- task :stop, :roles => :app do ; end
- end
- namespace :sphinx do
- [:start, :restart, :index].each do |t|
- desc "Runs the ts:#{t} task on the server."
- task t, :roles => :app do
- run("cd #{current_path}; /usr/bin/rake ts:#{t} RAILS_ENV=production")
- end
- end
- end
- namespace :config do
- desc "copy shared configurations to current"
- task :copy_shared_configurations, :roles => [:app] do
- %w[database.yml].each do |f|
- run "ln -nsf #{shared_path}/config/#{f} #{release_path}/config/#{f}"
- end
- end
- desc "reloads apache configuration to make site active"
- task :reload_apache do
- sudo "/etc/init.d/apache2 reload"
- end
- end
- namespace :gems do
- desc "Install gems"
- task :install, :roles => :app do
- run "cd #{current_path} && #{sudo} rake RAILS_ENV=production gems:install"
- end
- end
- namespace :init do
- desc "setting proper permissions for deploy user"
- task :set_permissions do
- sudo "chmod -R g+rw #{base_path}/#{application}"
- sudo "chown -R #{user}:#{group} #{base_path}/#{application}"
- end
- desc "create mysql db"
- task :create_database do
- set :db_root_user, 'root'#Capistrano::CLI.ui.ask("mysql super user: ") unless defined?(db_root_user)
- set :db_root_pass, Capistrano::CLI.password_prompt("#{db_root_user}'s database password: ") unless defined?(db_root_pass)
- set :db_user, "#{application}"
- set :db_pass, Capistrano::CLI.password_prompt("new database password: ") unless defined?(db_pass)
- # Create new user role, then create a database they can administer
- run "echo \"CREATE DATABASE #{application}_production\" | mysql -u #{db_root_user} --password=#{db_root_pass}"
- run "echo \"GRANT ALL PRIVILEGES ON #{application}_production.* TO '#{application}'@'localhost' IDENTIFIED BY '#{db_pass}' WITH GRANT OPTION;\" | mysql -u #{db_root_user} --password=#{db_root_pass}"
- end
- desc "enable site"
- task :enable_site do
- sudo "ln -nsf #{shared_path}/config/apache_site.conf #{apache_site_folder}/#{application}"
- end
- desc "create database.yml"
- task :database_yml do
- set :db_user, "#{application}"
- set :db_pass, Capistrano::CLI.password_prompt("new database password: ") unless defined?(db_pass)
- database_configuration = <<-DATABASE_YML
- login: &login
- adapter: mysql
- encoding: utf8
- database: #{application}_production
- host: localhost
- pool: 5
- username: #{db_user}
- password: #{db_pass}
- socket: /var/run/mysqld/mysqld.sock
- production:
- <<: *login
- DATABASE_YML
- run "mkdir -p #{shared_path}/config"
- put database_configuration, "#{shared_path}/config/database.yml"
- end
- desc "create vhost file"
- task :create_vhost do
- vhost_configuration = <<-VHOST
- <VirtualHost *:80>
- ServerName #{server_name}
- ServerAlias #{server_alias}
- DocumentRoot "#{base_path}/#{application}/current/public"
- RailsEnv production
- RailsAllowModRewrite off
- <directory "#{base_path}/#{application}/current/public">
- Order allow,deny
- Allow from all
- </directory>
- </VirtualHost>
- VHOST
- put vhost_configuration, "#{shared_path}/config/apache_site.conf"
- end
- end
Add Comment
Please, Sign In to add comment