lib/rush/box.rb in rush-0.3 vs lib/rush/box.rb in rush-0.4
- old
+ new
@@ -39,29 +39,42 @@
# trailing slash, or Rush::File otherwise.
def [](key)
filesystem[key]
end
- # Get the list of processes currently running on the box. Returns an array
- # of Rush::Process.
+ # Get the list of processes running on the box, not unlike "ps aux" in bash.
+ # Returns a Rush::ProcessSet.
def processes
- connection.processes.map do |ps|
- Rush::Process.new(ps, self)
- end
+ Rush::ProcessSet.new(
+ connection.processes.map do |ps|
+ Rush::Process.new(ps, self)
+ end
+ )
end
- # Execute a command in the standard unix shell. Options:
+ # Execute a command in the standard unix shell. Returns the contents of
+ # stdout if successful, or raises Rush::BashFailed with the output of stderr
+ # if the shell returned a non-zero value. Options:
#
# :user => unix username to become via sudo
# :env => hash of environment variables
+ # :background => run in the background (returns Rush::Process instead of stdout)
#
- # Example:
+ # Examples:
#
# box.bash '/etc/init.d/mysql restart', :user => 'root'
# box.bash 'rake db:migrate', :user => 'www', :env => { :RAILS_ENV => 'production' }
+ # box.bash 'mongrel_rails start', :background => true
#
def bash(command, options={})
- connection.bash(command_with_environment(command, options[:env]), options[:user])
+ cmd_with_env = command_with_environment(command, options[:env])
+
+ if options[:background]
+ pid = connection.bash(cmd_with_env, options[:user], true)
+ processes.find_by_pid(pid)
+ else
+ connection.bash(cmd_with_env, options[:user], false)
+ end
end
def command_with_environment(command, env) # :nodoc:
return command unless env