capistrano/capistrano — Issue #117: Callbacks being run twice
Author: OiNutter
Created: 2011-10-19 10:14:25+00:00
State: open

I'm getting a strange issue where my after callbacks are being called twice which is causing the deployment to fail as it's trying to create files that it's already created and therefore getting conflicts. Interestingly it is only displaying the `triggering after callbacks for ` message once but is executing the callbacks twice.

My deploy.rb is as follows:

# What is the name of the local application?
set :application, "tradeupandrecycle.com"

# What user is connecting to the remote server?
set :user, "root"

# Where is the local repository?
set :repository, "file:///home/tradeupa/git/tradeupandrecycle.git"
set :local_repository, " ssh://vserver/home/tradeupa/git/tradeupandrecycle.git"

# What is the production server domain?
role :web, "vserver"

# What remote directory hosts the production website?
set :deploy_to, "/home/tradeupa/public_html/"

# Is sudo required to manipulate files on the remote server?
set :use_sudo, false

# What version control solution does the project use?
set :scm, :git
set :branch, 'master'

# How are the project files being transferred?
set :deploy_via, :remote_cache

# Maintain a local repository cache. Speeds up the copy process.
set :copy_cache, true

# Ignore any local files?
set :copy_exclude, %w(.git,deployment,.project)

#enabled submodules
set :git_enable_submodules, 1

set :group_writable, false

ssh_options[:forward_agent] = true

after "deploy:setup", "summit:change_permissions", "summit:create_htaccess", "summit:create_shares"

after "deploy:symlink", "summit:change_permissions", "summit:switch_htaccess"
after "deploy:rollback", "summit:change_permissions"

namespace :summit do
#generates default htaccess file to redirect to current
task :create_htaccess, :roles =>:web do
run 'echo -e "Options +FollowSymlinks\nRewriteEngine On\nRewriteCond %{REQUEST_URI} !^/current/\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)$ /current/\$1 [NC,QSA]\n\nRewriteRule ^(/)?$ /current/ [NC,QSA]" > /home/tradeupa/www/.htaccess'
end

#create required shared folders
task :create_shares, :roles=>:web do
run 'mkdir /home/tradeupa/www/shared/uploads && sudo chmod 777 /home/tradeupa/www/shared/uploads'
run 'mkdir /home/tradeupa/www/shared/batches && sudo chmod 777 /home/tradeupa/www/shared/batches'
run 'mkdir /home/tradeupa/www/shared/config'
end

#update the permissions
task :change_permissions, :roles => :web do
run "sudo chown -R tradeupa:tradeupa #{deploy_to}"
run "sudo chmod 755 #{deploy_to}"
run "sudo chmod -R 755 #{deploy_to}releases"
end

#link the admin config file
task :link_admin_config do
run "ln -s #{shared_path}/configs/admin-config.json #{current_release}/admin/config/site/config.json"
end

#upload the admin config files
task :put_admin_config do
if(File.exists?("admin/config/site/config.json"))
upload("admin/config/site/config.json","#{shared_path}/configs/admin-config.json",:via => :scp, :mode => '755')
puts 'Admin config uploaded'
else
puts 'No JSON File To Upload'
end

if(File.exists?("admin/app/assets/css/sass/_colours.scss"))
upload("admin/app/assets/css/sass/_colours.scss","#{shared_path}/configs/admin-colours.scss",:via => :scp, :mode => '755')
puts 'Admin CSS constants uploaded'
else
puts 'No SASS File To Upload'
end
end

#downloads the admin config files
task :get_admin_config do
download("#{shared_path}/configs/admin-config.json","admin/config/site/config.json",:via => :scp)
download("#{shared_path}/configs/admin-colours.scss","admin/app/assets/css/sass/_colours.scss",:via => :scp)
end

#deploys admin config files
task :deploy_admin_config do
put_admin_config
link_admin_config
end

#replaces development htaccess with production version
task :switch_htaccess, :roles => :web do
run "mv #{current_release}/.htaccess #{current_release}/.htaccess-development"
run "cp #{current_release}/.htaccess-production #{current_release}/.htaccess"
end

end