Skip to content

Instantly share code, notes, and snippets.

@luizpicolo
Created July 28, 2014 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizpicolo/dbdff3ce8149798b265b to your computer and use it in GitHub Desktop.
Save luizpicolo/dbdff3ce8149798b265b to your computer and use it in GitHub Desktop.
Mina Deploy RollBack
desc "Rolls back the latest release"
task :rollback => :environment do
queue! %[echo "-----> Rolling back to previous release for instance: #{domain}"]
# Delete existing sym link and create a new symlink pointing to the previous release
queue %[echo -n "-----> Creating new symlink from the previous release: "]
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 2 | head -n 1]
queue! %[ls -Art "#{deploy_to}/releases" | sort | tail -n 2 | head -n 1 | xargs -I active ln -nfs "#{deploy_to}/releases/active" "#{deploy_to}/current"]
# Remove latest release folder (active release)
queue %[echo -n "-----> Deleting active release: "]
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1]
queue! %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1 | xargs -I active rm -rf "#{deploy_to}/releases/active"]
end
@elfuego
Copy link

elfuego commented May 7, 2015

When you reach more then 9 releases you may run into trouble with sort, it may sort your numbers like strings. I changed sort to sort -n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment