0
@@ -27,6 +27,8 @@ _cset :deploy_via, :checkout
0
_cset(:deploy_to) { "/u/apps/#{application}" }
0
_cset(:revision) { source.head }
0
+_cset :runner_admin, nil
0
# =========================================================================
0
# These variables should NOT be changed unless you are very confident in
0
# what you are doing. Make sure you understand all the implications of your
0
# another command, for executing that command as described below.
0
# If :run_method is :sudo (or :use_sudo is true), this executes the given command
0
-# via +sudo+. Otherwise is uses +run+. Further, if sudo is being used and :runner
0
-# is set, the command will be executed as the user given by :runner.
0
-def try_sudo(command=nil)
0
- as = fetch(:runner, "app")
0
+# via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
0
+# passed as the user to sudo as, if using sudo. If the :as key is not given,
0
+# it will default to whatever the value of the :admin_runner variable is,
0
+# which (by default) is unset.
0
+# THUS, if you want to try to run something via sudo, and what to use the
0
+# root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
0
+# someone else, you'd just do try_sudo('something', :as => "bob"). If you
0
+# always wanted sudo to run as a particular user, you could do
0
+# set(:admin_runner, "bob").
0
+ options = args.last.is_a?(Hash) ? args.pop : {}
0
+ raise ArgumentError, "too many arguments" if args.any?
0
+ as = options.fetch(:as, fetch(:admin_runner, nil))
0
via = fetch(:run_method, :sudo)
0
invoke_command(command, :via => via, :as => as)
0
@@ -108,6 +122,14 @@ def try_sudo(command=nil)
0
+# Same as sudo, but tries sudo with :as set to the value of the :runner
0
+# variable (which defaults to "app").
0
+ options = args.last.is_a?(Hash) ? args.pop : {}
0
+ args << options.merge(:as => fetch(:runner, "app"))
0
# =========================================================================
0
# These are the tasks that are available to help with deploying web apps,
0
# and specifically, Rails applications. You can have cap give you a summary
0
@@ -260,7 +282,7 @@ namespace :deploy do
0
task :restart, :roles => :app, :except => { :no_release => true } do
0
- try_
sudo "#{current_path}/script/process/reaper"
0
+ try_
runner "#{current_path}/script/process/reaper"
0
@@ -418,7 +440,7 @@ namespace :deploy do
0
the :use_sudo variable to false.
0
task :start, :roles => :app do
0
- run "cd #{current_path} && #{try_
sudo} nohup script/spin"
0
+ run "cd #{current_path} && #{try_
runner} nohup script/spin"
0
@@ -433,8 +455,8 @@ namespace :deploy do
0
the :use_sudo variable to false.
0
task :stop, :roles => :app do
0
- run "if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{try_sudo} #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi"
0
- try_sudo "#{current_path}/script/process/reaper -a kill"
0
+ run "if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{try_runner} #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi"
0
+ try_runner "#{current_path}/script/process/reaper -a kill"