Handbook: Bash
Launch a bash command (yeah, it's still going to be necessary for a while) from a box:
box.bash "git commit -m 'changes'"
stdout is returned, but if the bash command returns nonzero, an exception is raised with stderr.
begin
box.bash "git commit -m 'changes'"
rescue Rush::BashFailed => e
puts "Failed to commit, reason: #{e.message}"
end
Execute from a dir instead of a box in order to set that dir as the current directory before executing:
box['/var/www/myapp/'].bash 'mongrel_rails start'
Pass in a hash of variables to set the environment:
box['/var/www/myapp/'].bash 'mongrel_rails start', :env => { :RAILS_ENV => 'production' }
The :user parameter will use sudo capability, if you're root or an sudoer:
box.bash '/etc/init.d/nginx reload', :user => 'root'
