Avoiding the SUDO police with Capistrano

Posted on Sat Mar 25 13:56:00 UTC 2006

Turns out that by default, Capistrano is using sudo to delete everything (can I stop for a second and say that, for once, this is a bad default! At least on a shared hosted environment).

So anyway, I take a look at capistrano/recipes/standard.rb in my gems directory, and finds that there are the following 2 lines (conveniently placed at the beginning of the file):

set :use_sudo, true
set(:run_method) { use_sudo ? :sudo : :run }

Not a problem, let’s try to set :use_sudo to false in my confi/deploy.rb

set :use_sudo, false

Just to be sure, let’s do a dry run and check out what are the commands issued in this case to check that sudo is not called:

cap -P cleanup

Uh Ho again!

*** no old releases to clean up

:( oops. not only are my old releases not gone, but now I can’t rerun the script. Forutunately, the previous call to Capistrano had a log and I was able to log in to my host and run that massive rm -rf by hand.

Now, I was able to deploy an other release, and check whether setting :use_sudo works or not.

* executing “rm -rf …

It works! Phew!

And now I can rest assured that the SUDO police won’t take me away :)

Note: turns out “cap -P cleanup” is not too useful because it needs to get the list of what’s available on the server.

Posted in Quid Pro Quo, Rails  |  Tags  |  3 comments

Comments

  1. Matt White Matt White said // Apr 30, 2006 at 02:35 AM

    Thanks for posting this! I was trying to deploy to site5 and was having the same problem on a deploy with the spawner/spinner scripts. This took care of it!

  2. Andrew Dedman Andrew Dedman said // Jul 26, 2008 at 05:06 PM

    Thanks Pascal, just what I needed.

  3. Phil Phil said // Aug 01, 2008 at 02:07 AM

    bless you for posting this!

(leave url/email »)

Comment Markup Help