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.