Skip to content

Instantly share code, notes, and snippets.

@divineforest
Created September 17, 2012 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save divineforest/3737133 to your computer and use it in GitHub Desktop.
Save divineforest/3737133 to your computer and use it in GitHub Desktop.
Lock deploy in Capistrano (only 1 deploy at a moment)
set :deploy_lock_file, "#{shared_path}/tmp/deploing_lock_file"
namespace :deploy do
desc "Check if somebody already is deploing"
task :check_lock do
result = capture("if [ -f #{deploy_lock_file} ]; then cat #{deploy_lock_file}; else echo '0'; fi").strip
if result != '0'
run "echo '#{result} already deploing' 1>&2"
exit
end
end
desc "Mark that I'm deploing"
task :lock do
current_user = `whoami`.strip
run "echo '#{current_user}' > #{deploy_lock_file}"
end
desc "Clear deploy lock file after deploy"
task :unlock do
run "rm #{deploy_lock_file}"
end
end
before "deploy", "deploy:check_lock"; before "deploy:migrations", "deploy:check_lock"
before "deploy", "deploy:lock"; before "deploy:migrations", "deploy:lock"
after "deploy", "deploy:unlock"; after "deploy:migrations", "deploy:unlock"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment