Skip to content

Instantly share code, notes, and snippets.

@narkisr
Created Feb 4, 2015
Embed
What would you like to do?
capistrano 3 jar deployment
STAMP = Time.now.strftime('%H_%M_%S_%L')
ROOT = "/u/apps/#{fetch(:application)}"
def release
"#{ROOT}/releases/#{STAMP}"
end
def current
"#{ROOT}/current"
end
namespace :deploy do
desc 'clears n last builds'
task :purge do
on roles(:all) do
total = capture("ls -la #{ROOT}/releases | wc -l").to_i
if(total > 9)
execute "cd #{ROOT}/releases && ls -tr | head -n -5 | xargs sudo rm -rf"
end
end
end
task :stop do
on roles(:all) do |host|
execute "sudo service #{fetch(:service)} stop 2>&1 | grep -E 'Unknown|waiting'"
end
end
task :start do
on roles(:all) do |host|
execute :sudo, :service, fetch(:service), 'start'
end
end
task :update do
invoke 'deploy:purge'
invoke 'deploy:stop'
on roles(:all) do
execute :sudo, :mkdir, release, '-p'
execute :sudo, :wget, '-q', artifact(fetch(:application),ENV['build']), '-P', release
end
invoke 'deploy:symlink'
invoke 'deploy:start'
end
task :symlink do
on roles(:all) do
execute :sudo, :rm , '-f', current
execute :sudo, :ln , '-s' , release, current
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment