deploy.rb

Path: lib/capistrano/recipes/deploy.rb
Last Update: Sun Mar 21 00:00:47 -0600 2010

Required files

yaml   capistrano/recipes/deploy/scm   capistrano/recipes/deploy/strategy   erb  

Methods

Public Instance methods

[Source]

   # File lib/capistrano/recipes/deploy.rb, line 5
5: def _cset(name, *args, &block)
6:   unless exists?(name)
7:     set(name, *args, &block)
8:   end
9: end

tests if the given command is present on the local system

[Source]

     # File lib/capistrano/recipes/deploy.rb, line 102
102: def command_present?(cmd)
103:   executable = cmd.to_s.split(" ").first
104:   unless system("which #{executable}")
105:     logger.important "executable '#{executable}' not present or not in $PATH on the local system!"
106:   end
107: end

Auxiliary helper method for the `deploy:check’ task. Lets you set up your own dependencies.

[Source]

    # File lib/capistrano/recipes/deploy.rb, line 76
76: def depend(location, type, *args)
77:   deps = fetch(:dependencies, {})
78:   deps[location] ||= {}
79:   deps[location][type] ||= []
80:   deps[location][type] << args
81:   set :dependencies, deps
82: end

logs the command then executes it locally. returns the command output as a string

[Source]

    # File lib/capistrano/recipes/deploy.rb, line 95
95: def run_locally(cmd)
96:   logger.trace "executing locally: #{cmd.inspect}" if logger
97:   command_present?(cmd)
98:   `#{cmd}`
99: end

Same as sudo, but tries sudo with :as set to the value of the :runner variable (which defaults to "app").

[Source]

     # File lib/capistrano/recipes/deploy.rb, line 142
142: def try_runner(*args)
143:   options = args.last.is_a?(Hash) ? args.pop : {}
144:   args << options.merge(:as => fetch(:runner, "app"))
145:   try_sudo(*args)
146: end

If a command is given, this will try to execute the given command, as described below. Otherwise, it will return a string for use in embedding in another command, for executing that command as described below.

If :run_method is :sudo (or :use_sudo is true), this executes the given command via sudo. Otherwise is uses run. If :as is given as a key, it will be passed as the user to sudo as, if using sudo. If the :as key is not given, it will default to whatever the value of the :admin_runner variable is, which (by default) is unset.

THUS, if you want to try to run something via sudo, and what to use the root user, you‘d just to try_sudo(‘something’). If you wanted to try_sudo as someone else, you‘d just do try_sudo(‘something’, :as => "bob"). If you always wanted sudo to run as a particular user, you could do set(:admin_runner, "bob").

[Source]

     # File lib/capistrano/recipes/deploy.rb, line 124
124: def try_sudo(*args)
125:   options = args.last.is_a?(Hash) ? args.pop : {}
126:   command = args.shift
127:   raise ArgumentError, "too many arguments" if args.any?
128: 
129:   as = options.fetch(:as, fetch(:admin_runner, nil))
130:   via = fetch(:run_method, :sudo)
131:   if command
132:     invoke_command(command, :via => via, :as => as)
133:   elsif via == :sudo
134:     sudo(:as => as)
135:   else
136:     ""
137:   end
138: end

Temporarily sets an environment variable, yields to a block, and restores the value when it is done.

[Source]

    # File lib/capistrano/recipes/deploy.rb, line 86
86: def with_env(name, value)
87:   saved, ENV[name] = ENV[name], value
88:   yield
89: ensure
90:   ENV[name] = saved
91: end

[Validate]