Rollback on task fail

148 views
Skip to first unread message

Rafa García

unread,
Oct 22, 2014, 5:33:09 AM10/22/14
to capis...@googlegroups.com
Hi,

  I have two applications deployed with Capistrano. In the last deploy we had a problem with one of them but rollback was not executed automatically.

  Deploys are done automatically with jenkins. I achieved to execute rollback inside jenkins task capturing status code in a condition and then executing rollback task.

  But I'm wondering (if it's possible) how I can do a rollback automatically if any of the deploy tasks fails from Capistrano?

Thanks

Lee Hambley

unread,
Oct 22, 2014, 6:20:49 AM10/22/14
to capistrano
Hi Rafa, (welcome back!) 

Which version, two or three ?

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/CALgP05YcH%3DVRDXYt4HF816ETs0Eb_akUBCn9%2BwmKZsVXigAu5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Rafa García

unread,
Oct 22, 2014, 6:23:36 AM10/22/14
to capis...@googlegroups.com
Hi Lee :D

  I'm using Capistrano v3.

Rafa García

unread,
Oct 22, 2014, 6:25:05 AM10/22/14
to capis...@googlegroups.com
Capistrano v3 (3.2.1)

PD: I forgot to paste gem version

Lee Hambley

unread,
Oct 22, 2014, 6:32:27 AM10/22/14
to capistrano
Haha, no worries.

We actually elected in v3 not to do an automatic rollback, because many people found it inconvenient to debug, and we're essentially defaulting to deleting stuff in production. 

There was many weird edge cases with assets being incorrecly removed, etc, etc, et... nothing that was 100% our fault, but we figured just failing clearly was a better way to handle that.

In your own code, you can rescue it, and Rake::Task["deploy:rollback"].invoke, but it's probably wiser in this case (and, in my cases, usually) to do a switch on the shell, decide what to do, and then rollback.

Of course a rollback is weird, because we have to delete the folder in order to keep the "newest release" logic working, but often if you had a bad deploy, you need the contents of that folder to do some forensics.

For that reason, keep doing what you are doing, and consider adding a task to copy the broken release to a safe place, before it's removed by it is removed in the rollback flow.

If for some reason cap is failing, but you get a zero-exit status, then let me know specifically what's going wrong, and I'll fix that, you should be able to rely on our exit statuses being informative.

Ryan E

unread,
Oct 27, 2014, 8:47:18 AM10/27/14
to capis...@googlegroups.com
Hi Lee

I was looking at this the other day and had a couple of questions.

1. You mentioned that it is a good idea to "copy the broken release to a safe place". Doesn't the rollback task already handle this for you? When I run a rollback, I end up with a rolled-back-release-#{last_release}.tar.gz in the deploy directory. 

2. Do you have any suggestions about how you would decide whether it is safe to issue a rollback based on the exit code of the cap command? If for some reason the deploy failed before it created the new release directory, it looks like running a rollback would do the wrong thing and rollback the current good release. As far as I can tell, cap always returns an exit code of 1 when it fails so I am not sure how to use that to determine if we should actually rollback or not.

Thanks!
Ryan

Michael Richardson

unread,
Oct 27, 2014, 5:46:55 PM10/27/14
to capis...@googlegroups.com

Ryan E <rya...@gmail.com> wrote:
> 1. You mentioned that it is a good idea to "copy the broken release to
> a safe place". Doesn't the rollback task already handle this for you?
> When I run a rollback, I end up with a
> rolled-back-release-#{last_release}.tar.gz in the deploy directory.

That doesn't happen if it's really a bad deploy.
The directory gets nuked...

My usual trick is to insert capistrano step which basically turns into either
an interactive shell, or has "sleep 10000" on it, so that I can login and
poke at things.

--
] Never tell me the odds! | ipv6 mesh networks [
] Michael Richardson, Sandelman Software Works | network architect [
] m...@sandelman.ca http://www.sandelman.ca/ | ruby on rails [

Reply all
Reply to author
Forward
0 new messages