load 'deploy' namespace :deploy do desc <<-DESC Prepares one or more servers for deployment. Before you can use any \ of the Capistrano deployment tasks with your project, you will need to \ make sure all of your servers have been prepared with `cap deploy:setup'. When \ you add a new server to your cluster, you can easily run the setup task \ on just that server by specifying the HOSTS environment variable: $ cap HOSTS=new.server.com deploy:setup It is safe to run this task on servers that have already been set up; it \ will not destroy any deployed revisions or data. DESC task :setup, :except => { :no_release => true } do dirs = [deploy_to, releases_path, shared_path] dirs += %w(system).map { |d| File.join(shared_path, d) } run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}" end desc <<-DESC [internal] Touches up the released code. This is called by update_code \ after the basic deploy finishes. This task will make the release group-writable (if the :group_writable \ variable is set to true, which is the default). It will then set up a \ symlink to the shared directory for the system \ directory, and will lastly touch all assets in public/images, \ public/stylesheets, and public/javascripts so that the times are \ consistent (so that asset timestamping works). This touch process \ is only carried out if the :normalize_asset_timestamps variable is \ set to true, which is the default. DESC task :finalize_update, :except => { :no_release => true } do run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) run <<-CMD rm -rf #{latest_release}/public/system && mkdir -p #{latest_release}/public && mkdir -p #{latest_release}/tmp && ln -s #{shared_path}/system #{latest_release}/public/system CMD end desc <<-DESC Restarts your application. This works by touching tmp/restart.txt \ file under the current path (see Passenger docs). DESC task :restart, :roles => :app, :except => { :no_release => true } do run "touch #{current_path}/tmp/restart.txt" end tasks.delete(:migrate) tasks.delete(:migrations) desc <<-DESC Deploys and starts a `cold' application. This is useful if you have not \ deployed your application before, or if your application is (for some \ other reason) not currently running. It will deploy the code. DESC task :cold do update end tasks.delete(:start) tasks.delete(:stop) end