public
Description: Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Only use :runner for tasks that affect the application's execution.

This includes deploy:start, deploy:stop, and deploy:restart. The
other sudo-enabled tasks (deploy:cleanup and deploy:setup) will try
sudo as the :admin_runner variable, allowing people to either leave
that value unset (causing those tasks to try sudo as root), or to
set it to some other value.
Jamis Buck (author)
Thu Jun 05 20:30:42 -0700 2008
commit  41c0da75259f92632e22d12606350b837b286c39
tree    1081fb50bc7c5d35ba40b35731c725ed6225bec7
parent  2ac1906a3ab0bda997ca3b028b9b20d222faf3fe
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *unreleased*
0
 
0
+* Only make deploy:start, deploy:stop, and deploy:restart try sudo as :runner. The other sudo-enabled tasks (deploy:setup, deploy:cleanup, etc.) will now use the :admin_runner user (which by default is unset). [Jamis Buck]
0
+
0
 * Make sure triggers defined as a block inherit the scope of the task they are attached to, instead of the task they were called from [Jamis Buck]
0
 
0
 * Make deploy:upload use the upload() helper for more efficient directory processing [Jamis Buck]
...
27
28
29
 
 
30
31
32
...
94
95
96
97
98
99
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
102
103
...
108
109
110
 
 
 
 
 
 
 
 
111
112
113
...
260
261
262
263
 
264
265
266
...
418
419
420
421
 
422
423
424
...
433
434
435
436
437
 
 
438
439
440
...
27
28
29
30
31
32
33
34
...
96
97
98
 
 
 
 
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
282
283
284
 
285
286
287
288
...
440
441
442
 
443
444
445
446
...
455
456
457
 
 
458
459
460
461
462
0
@@ -27,6 +27,8 @@ _cset :deploy_via, :checkout
0
 _cset(:deploy_to) { "/u/apps/#{application}" }
0
 _cset(:revision)  { source.head }
0
 
0
+_cset :runner_admin, nil
0
+
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
@@ -94,10 +96,22 @@ end
0
 # another command, for executing that command as described below.
0
 #
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
+#
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
+def try_sudo(*args)
0
+  options = args.last.is_a?(Hash) ? args.pop : {}
0
+  command = args.shift
0
+  raise ArgumentError, "too many arguments" if args.any?
0
+
0
+  as = options.fetch(:as, fetch(:admin_runner, nil))
0
   via = fetch(:run_method, :sudo)
0
   if command
0
     invoke_command(command, :via => via, :as => as)
0
@@ -108,6 +122,14 @@ def try_sudo(command=nil)
0
   end
0
 end
0
 
0
+# Same as sudo, but tries sudo with :as set to the value of the :runner
0
+# variable (which defaults to "app").
0
+def try_runner(*args)
0
+  options = args.last.is_a?(Hash) ? args.pop : {}
0
+  args << options.merge(:as => fetch(:runner, "app"))
0
+  try_sudo(*args)
0
+end
0
+
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
       set :use_sudo, false
0
   DESC
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
   end
0
 
0
   desc <<-DESC
0
@@ -418,7 +440,7 @@ namespace :deploy do
0
     the :use_sudo variable to false.
0
   DESC
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
   end
0
 
0
   desc <<-DESC
0
@@ -433,8 +455,8 @@ namespace :deploy do
0
     the :use_sudo variable to false.
0
   DESC
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"
0
   end
0
 
0
   namespace :pending do

Comments