Skip to content
This repository has been archived by the owner on Jul 14, 2018. It is now read-only.

Latest commit

 

History

History
46 lines (26 loc) · 2.26 KB

2.x-DSL-Action-Invocation-Sudo.md

File metadata and controls

46 lines (26 loc) · 2.26 KB

Definition

sudo(options={})
sudo(command, options={}, &block)

Module

Capistrano::Configuration::Actions::Invocation

The sudo action is used to execute commands via [http://en.wikipedia.org/wiki/Sudo sudo]. It can be used in either of two ways (although one is deprecated). Although you could use sudo directly in your run() invocations, this helper makes it possible for Capistrano to prompt you for the sudo password when the remote server(s) prompt for it.

sudo(options={})

This use of sudo does not actually execute anything. Instead, it returns a string containing the sudo command to execute. This lets you embed it in commands invoked via [[run]], which in turn lets you build arbitrarily complex commands that use sudo.

run "#{sudo} apachectl restart"
run "#{sudo :as => 'bob'} crontab -l"
run "cd /u/apps/social && #{sudo} script/restart"
run "if [ ! -d /u/apps ]; then #{sudo} mkdir -p /u/apps; fi"

Arguments

Options

:as

Specify the user to sudo as. This defaults to nil, which is typically the same as specifying "root" as the user.

Variables

:sudo

Specify the path to sudo on the servers. This defaults to just "sudo", but if sudo on your servers is either in a non-standard location or is named something other than "sudo", you can set this variable accordingly.

:sudo_password

Specify the password ''prompt'' (not the password itself!) that sudo should use when asking for a password. You shouldn't ever need to change this (the default is "sudo password: "), since this is only needed so that Capistrano can recognize the sudo prompt and pass the prompt on to the user. Setting the value of this variable to the empty string will cause Capistrano to not request any specific password prompt.

sudo(command, options={}, &block)

This use of sudo is deprecated and is included only for backwards compatibility with some Capistrano recipes. It is essentially identical to run(), except that it will prefix the command with sudo (see the first use of the sudo()).

sudo "apachectl restart"
sudo "crontab -l", :as => "bob"

Note that this syntax does not allow complicated shell script commands, or chaining commands together in a single invocation. See the first syntax for that.