Run from Capistrano
Posted by Christopher Rigor on March 8, 2008
Filed Under Ruby on Rails
You can run shell commands from capistrano using the run method. For example, to create a symlink from the shared directory to the current directory, you’ll write
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
run can also take a block like this
run "rsync /path/to/file host:/path/to/file" do |channel, stream, text|
logger.info "[#{stream}] #{text}"
output = case text
when /\bpassword.*:/i
"#{password}\n"
when %r{\(yes/no\)}
"yes\n"
end
channel.send_data(output) if output
end
When you run a command it might ask for your password. To handle this in capistrano, use send_data to send a response.
Check lib/capistrano/recipes/deploy/scm/subversion.rb on the capistrano gem to see how capistrano handles subversion commands.