Class: Capistrano::Configuration
- Inherits:
-
Object
- Object
- Capistrano::Configuration
- Defined in:
- lib/palmtree/capistrano_extensions/configuration_extensions.rb
Instance Method Summary collapse
-
#as_root ⇒ Object
Run a task using root account.
-
#run_as_root(shell_command) ⇒ Object
Run a command using the root account.
-
#run_with_input(shell_command, input_query = /^Password/) ⇒ Object
Run a command and ask for input when input_query is seen.
-
#sudo_stream(command, outfunc = :puts) ⇒ Object
Run a command using sudo and continuously pipe the results back to the console.
-
#sudo_with_input(shell_command, input_query = /^Password/) ⇒ Object
Run a command using sudo and ask for input when a regular expression is seen.
Instance Method Details
#as_root ⇒ Object
Run a task using root account.
Some linux distros/VPS providers only give you a root login when you install.
tempuser: contains the value replaced by ‘root’ for the duration of this call
58 59 60 61 62 |
# File 'lib/palmtree/capistrano_extensions/configuration_extensions.rb', line 58 def as_root() std.connect_as_root do |tempuser| yield tempuser end end |
#run_as_root(shell_command) ⇒ Object
Run a command using the root account.
Some linux distros/VPS providers only give you a root login when you install.
47 48 49 50 51 |
# File 'lib/palmtree/capistrano_extensions/configuration_extensions.rb', line 47 def run_as_root(shell_command) std.connect_as_root do |tempuser| run shell_command end end |
#run_with_input(shell_command, input_query = /^Password/) ⇒ Object
Run a command and ask for input when input_query is seen. Sends the response back to the server.
input_query
is a regular expression that defaults to /^Password/.
Can be used where run
would otherwise be used.
run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
17 18 19 |
# File 'lib/palmtree/capistrano_extensions/configuration_extensions.rb', line 17 def run_with_input(shell_command, input_query=/^Password/) handle_command_with_input(:run, shell_command, input_query) end |
#sudo_stream(command, outfunc = :puts) ⇒ Object
Run a command using sudo and continuously pipe the results back to the console.
Similar to the built-in stream
, but for privileged users.
34 35 36 37 38 39 40 41 42 |
# File 'lib/palmtree/capistrano_extensions/configuration_extensions.rb', line 34 def sudo_stream(command, outfunc = :puts) sudo(command) do |ch, stream, out| self.send(outfunc, out) if stream == :out if stream == :err puts "[err : #{ch[:host]}] #{out}" break end end end |
#sudo_with_input(shell_command, input_query = /^Password/) ⇒ Object
Run a command using sudo and ask for input when a regular expression is seen. Sends the response back to the server.
See also run_with_input
input_query
is a regular expression
27 28 29 |
# File 'lib/palmtree/capistrano_extensions/configuration_extensions.rb', line 27 def sudo_with_input(shell_command, input_query=/^Password/) handle_command_with_input(:sudo, shell_command, input_query) end |