Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set :domain, "111.222.333.444"
- set :application, "YOURAPP"
- set :keep_releases, 2
- set :repository, "git@#{domain}:#{application}.git"
- set :scm, :git
- set :deploy_via, :remote_cache
- set :deploy_to, "/var/www/#{application}"
- set :user, "deploy"
- set :runner, "mongrel"
- set :use_sudo, :false
- set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
- role :app, "#{domain}"
- role :web, "#{domain}"
- role :db, "#{domain}", :primary => true
- # == CONFIG ====================================================================
- namespace :init do
- namespace :config do
- desc "Create database.yml"
- task :database do
- set :db_user, Capistrano::CLI.ui.ask("database user: ")
- set :db_pass, Capistrano::CLI.password_prompt("database password: ")
- database_configuration =<<-EOF
- ---
- login: &login
- adapter: mysql
- database: #{application}
- host: localhost
- username: #{db_user}
- password: #{db_pass}
- production:
- <<: *login
- EOF
- run "mkdir -p #{shared_path}/config"
- put database_configuration, "#{shared_path}/config/database.yml"
- end
- desc "Create mongrel_cluster.yml"
- task :mongrel do
- mongrel_cluster_configuration = <<-EOF
- ---
- user: mongrel
- cwd: #{current_path}
- log_file: #{current_path}/log/mongrel.log
- port: "8000"
- environment: production
- group: mongrel
- address: 127.0.0.1
- pid_file: #{current_path}/tmp/pids/mongrel.pid
- servers: 3
- EOF
- run "mkdir -p #{shared_path}/config"
- put mongrel_cluster_configuration, "#{shared_path}/config/mongrel_cluster.yml"
- end
- desc "Symlink shared configurations to current"
- task :localize, :roles => [:app] do
- %w[mongrel_cluster.yml database.yml].each do |f|
- run "ln -nsf #{shared_path}/config/#{f} #{current_path}/config/#{f}"
- end
- end
- end
- end
- # == NGINX =====================================================================
- namespace :nginx do
- desc "Start Nginx on the app server."
- task :start, :roles => :app do
- sudo "/etc/init.d/nginx start"
- end
- desc "Restart the Nginx processes on the app server by starting and stopping the cluster."
- task :restart , :roles => :app do
- sudo "/etc/init.d/nginx restart"
- end
- desc "Stop the Nginx processes on the app server."
- task :stop , :roles => :app do
- sudo "/etc/init.d/nginx stop"
- end
- end
- # == DATABASE ==================================================================
- namespace :db do
- desc "Backup your Database to #{shared_path}/db_backups"
- task :backup, :roles => :db, :only => {:primary => true} do
- set :db_user, Capistrano::CLI.ui.ask("Database user: ")
- set :db_pass, Capistrano::CLI.password_prompt("Database password: ")
- now = Time.now
- run "mkdir -p #{shared_path}/backup"
- backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
- set :backup_file, "#{shared_path}/backup/#{application}-snapshot-#{backup_time}.sql"
- run "mysqldump --add-drop-table -u #{db_user} -p #{db_pass} #{application} --opt | bzip2 -c > #{backup_file}.bz2"
- end
- end
- # == MONGREL ===================================================================
- namespace :deploy do
- desc "Start mongrel cluster"
- task :start do
- run "cd #{current_path} && sudo mongrel_rails cluster::start"
- end
- desc "Stop mongrel cluster"
- task :stop do
- run "cd #{current_path} && sudo mongrel_rails cluster::stop"
- end
- desc "Restart mongrel cluster"
- task :restart do
- run "cd #{current_path} && sudo mongrel_rails cluster::restart"
- end
- end
- # == TASKS =====================================================================
- before "deploy:migrate", "db:backup"
- after "deploy", "deploy:cleanup"
- after "deploy:migrations", "deploy:cleanup"
- after "deploy:setup", "init:config:database"
- after "deploy:setup", "init:config:mongrel"
- after "deploy:symlink", "init:config:localize"
- task :after_update_code do
- sudo "chown mongrel:mongrel #{release_path}/tmp -R"
- sudo "chown mongrel:mongrel #{release_path}/log -R"
- sudo "chown mongrel:mongrel #{shared_path}/pids -R"
- end
Add Comment
Please, Sign In to add comment