Top Level Namespace
Defined Under Namespace
Modules: DaemonKit, Nanite Classes: File, Object, Sample, String, Thor
Constant Summary collapse
- DAEMON_ENV =
'test'
- DAEMON_ROOT =
Don’t change this file! Configure your daemon in config/environment.rb
"#{File.(File.dirname(__FILE__))}/.."
Instance Method Summary collapse
- #_cset(name, *args, &block) ⇒ Object
-
#depend(location, type, *args) ⇒ Object
Auxiliary helper method for the ‘deploy:check’ task.
-
#run_locally(cmd) ⇒ Object
logs the command then executes it locally.
-
#try_runner(*args) ⇒ Object
Same as sudo, but tries sudo with :as set to the value of the :runner variable (which defaults to “app”).
-
#try_sudo(*args) ⇒ Object
If a command is given, this will try to execute the given command, as described below.
-
#with_env(name, value) ⇒ Object
Temporarily sets an environment variable, yields to a block, and restores the value when it is done.
Instance Method Details
#_cset(name, *args, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 5 def _cset(name, *args, &block) unless exists?(name) set(name, *args, &block) end end |
#depend(location, type, *args) ⇒ Object
Auxiliary helper method for the ‘deploy:check’ task. Lets you set up your own dependencies.
81 82 83 84 85 86 87 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 81 def depend(location, type, *args) deps = fetch(:dependencies, {}) deps[location] ||= {} deps[location][type] ||= [] deps[location][type] << args set :dependencies, deps end |
#run_locally(cmd) ⇒ Object
logs the command then executes it locally. returns the command output as a string
100 101 102 103 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 100 def run_locally(cmd) logger.trace "executing locally: #{cmd.inspect}" if logger `#{cmd}` end |
#try_runner(*args) ⇒ Object
Same as sudo, but tries sudo with :as set to the value of the :runner variable (which defaults to “app”).
138 139 140 141 142 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 138 def try_runner(*args) = args.last.is_a?(Hash) ? args.pop : {} args << .merge(:as => fetch(:runner, "app")) try_sudo(*args) end |
#try_sudo(*args) ⇒ Object
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”).
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 120 def try_sudo(*args) = args.last.is_a?(Hash) ? args.pop : {} command = args.shift raise ArgumentError, "too many arguments" if args.any? as = .fetch(:as, fetch(:admin_runner, nil)) via = fetch(:run_method, :sudo) if command invoke_command(command, :via => via, :as => as) elsif via == :sudo sudo(:as => as) else "" end end |
#with_env(name, value) ⇒ Object
Temporarily sets an environment variable, yields to a block, and restores the value when it is done.
91 92 93 94 95 96 |
# File 'lib/daemon_kit/deployment/capistrano.rb', line 91 def with_env(name, value) saved, ENV[name] = ENV[name], value yield ensure ENV[name] = saved end |