Lars Pind

internet software, coaching, and entrepreneurship

Lars Pind - internet software, coaching, and entrepreneurship
Check out Coach TV, my video blog on happiness and personal development for geeks.

[Rails] Make capistrano ask for the password first

June 08, 2006 · See comments

I frequently find myself doing rake deploy with capistrano, and then wander off to do something else, while the checkout process runs its minute-long course. And then I forget what I was doing, and only 15 minutes later stumble upon that shell buffer again, only to discover that it’s still sitting there, waiting for my sudo password so it can restart the dispatchers.

Well, with this little snippet in my deploy.rb, it now asks for my sudo password up-front, so it’ll still be cached and valid when it really needs it at the end:

task :before_deploy, :roles => :app do 
  send(run_method, "date")
end

That’s it: Force it to execute some shell command using sudo. It doesn’t matter which, so long as it doesn’t actually do anything. I chose date. Calling run_method instead of sudo directly will ensure that if you’re not using sudo, it won’t ask for your password here, either.

blog comments powered by Disqus

Comments ↓

  • 1 Sean Treadway // Jun 08, 2006 at 03:29 AM

    Brilliant. I actually just ran into the same problem today.
  • 2 Lars Pind // Jun 08, 2006 at 12:18 PM

    I'm glad it could be of use. Rock on.
  • 3 DHH // Jun 09, 2006 at 04:22 AM

    You can also just pass "-p" to your capistrano call. Like "cap deploy -p". That'll force the question up front.
  • 4 Lars Pind // Jun 09, 2006 at 11:01 AM

    Haha, thanks, David, I was always using the "rake" version directly, so I never noticed.