Module | Capistrano::Configuration::Actions::Invocation |
In: |
lib/capistrano/configuration/actions/invocation.rb
|
Merges the various default command options into the options hash and returns the result. The default command options that are understand are:
Executes different commands in parallel. This is useful for commands that need to be different on different hosts, but which could be otherwise run in parallel.
The options parameter is currently unused.
Example:
task :restart_everything do parallel do |session| session.when "in?(:app)", "/path/to/restart/mongrel" session.when "in?(:web)", "/path/to/restart/apache" session.when "in?(:db)", "/path/to/restart/mysql" end end
Each command may have its own callback block, for capturing and responding to output, with semantics identical to run:
session.when "in?(:app)", "/path/to/restart/mongrel" do |ch, stream, data| # ch is the SSH channel for this command, used to send data # back to the command (e.g. ch.send_data("password\n")) # stream is either :out or :err, for which stream the data arrived on # data is a string containing data sent from the remote command end
Also, you can specify a fallback command, to use when none of the conditions match a server:
session.else "/execute/something/else"
The string specified as the first argument to when may be any valid Ruby code. It has access to the following variables and methods:
For example:
session.when "server.host =~ /app/", "/some/command" session.when "server.host == configuration[:some_var]", "/another/command" session.when "in?(:web) || in?(:app)", "/more/commands"
See run for a description of the valid options.
Execute the given command on all servers that are the target of the current task. If a block is given, it is invoked for all output generated by the command, and should accept three parameters: the SSH channel (which may be used to send data back to the remote process), the stream identifier (:err for stderr, and :out for stdout), and the data that was received.
The options hash may include any of the following keys:
Note that if you set these keys in the default_run_options Capistrano variable, they will apply for all invocations of run, invoke_command, and parallel.
Returns the command string used by capistrano to invoke a comamnd via sudo.
run "#{sudo :as => 'bob'} mkdir /path/to/dir"
It can also be invoked like run, but executing the command via sudo. This assumes that the sudo password (if required) is the same as the password for logging in to the server.
sudo "mkdir /path/to/dir"
Also, this method understands a :sudo configuration variable, which (if specified) will be used as the full path to the sudo executable on the remote machine:
set :sudo, "/opt/local/bin/sudo"
If you know what you‘re doing, you can also set :sudo_prompt, which tells capistrano which prompt sudo should use when asking for a password. (This is so that capistrano knows what prompt to look for in the output.) If you set :sudo_prompt to an empty string, Capistrano will not send a preferred prompt.