Created
September 17, 2012 12:58
-
-
Save divineforest/3737133 to your computer and use it in GitHub Desktop.
Lock deploy in Capistrano (only 1 deploy at a moment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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