Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'palmtree/recipes/mongrel_cluster'
- set :domain, "dev.mysite.com"
- set :application, "mysite"
- set :keep_releases, 3
- set :repository, "svn://#{domain}/#{application}/trunk"
- set :scm, :subversion
- set :deploy_via, :export
- set :deploy_to, "/var/www/#{application}"
- set :user, "deploy"
- set :runner, "mongrel"
- set :use_sudo, :true
- 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_host, Capistrano::CLI.ui.ask("database host: ")
- set :db_user, Capistrano::CLI.ui.ask("database user: ")
- set :db_pass, Capistrano::CLI.password_prompt("database password: ")
- database_configuration =<<-EOF
- ---
- production:
- adapter: mysql
- database: #{application}
- host: #{db_host}
- username: #{db_user}
- password: #{db_pass}
- EOF
- run "mkdir -p #{shared_path}/config"
- put database_configuration, "#{shared_path}/config/database.yml"
- end
- desc "Create backgroundrb.yml"
- task :backgroundrb, :roles => :app do
- backgroundrb_configuration = <<-EOF
- :backgroundrb:
- :ip: 127.0.0.1
- :port: 22222
- :environment: production
- EOF
- run "mkdir -p #{shared_path}/config"
- put backgroundrb_configuration, "#{shared_path}/config/backgroundrb.yml"
- end
- desc "Create mongrel_cluster.yml"
- task :mongrel, :roles => [:app] do
- mongrel_cluster_configuration = <<-EOF
- ---
- user: mongrel
- cwd: #{current_path}
- log_file: #{current_path}/log/mongrel.log
- port: "9000"
- 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[memcached.yml mongrel_cluster.yml amazon_s3.yml amazon_sqs.yml database.yml backgroundrb.yml].each do |f|
- run "rm -f #{current_path}/config/#{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
- # == BACKGROUNDRB ==============================================================
- namespace :drb do
- desc 'Start backgroundrb'
- task :start, :roles => :app do
- run "#{current_path}/script/backgroundrb start"
- end
- desc 'Stop backgroundrb'
- task :stop, :roles => :app do
- run "#{current_path}/script/backgroundrb stop"
- end
- desc 'Restart backgroundrb'
- task :restart, :roles => :app do
- stop
- start
- end
- end
- # == MONGREL ===================================================================
- namespace :deploy do
- desc "Start mongrel cluster"
- task :start, :roles => :app do
- run "cd #{current_path} && sudo mongrel_rails cluster::start"
- end
- desc "Stop mongrel cluster"
- task :stop, :roles => :app do
- run "cd #{current_path} && sudo mongrel_rails cluster::stop"
- end
- desc "Restart mongrel cluster"
- task :restart, :roles => :app do
- run "cd #{current_path} && sudo mongrel_rails cluster::restart"
- end
- end
- # == TASKS =====================================================================
- 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, :roles => :app 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"
- sudo "chmod 777 #{release_path}/public/javascripts"
- sudo "chmod 777 #{release_path}/public/stylesheets"
- sudo "chmod +x #{release_path}/script/backgroundrb"
- drb:restart
- end
Add Comment
Please, Sign In to add comment