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
Fix deployment recipes to use the updated sudo helper
Jamis Buck (author)
Sat May 24 20:32:38 -0700 2008
commit  19e6e3b9c6d002bdccc668172efb1b70462484e8
tree    f75515d082abaea3a462bed4623624d5aa1fefff
parent  b45290e6ae3acce465ab5b7b8a82b7ad73a022e3
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *unreleased*
0
 
0
+* Fix deployment recipes to use the updated sudo helper [Jamis Buck]
0
+
0
 * Enhance the sudo helper so it can be used to return the command, instead of executing it [Jamis Buck]
0
 
0
 * Revert "make sudo helper play nicely with complex command chains", since it broke stuff [Jamis Buck]
...
89
90
91
 
 
 
 
92
93
94
95
 
96
97
98
 
 
 
 
 
 
 
99
100
101
...
131
132
133
134
 
135
136
137
...
413
414
415
416
 
417
418
419
...
428
429
430
431
 
432
433
434
...
89
90
91
92
93
94
95
96
97
98
 
99
100
101
 
102
103
104
105
106
107
108
109
110
111
...
141
142
143
 
144
145
146
147
...
423
424
425
 
426
427
428
429
...
438
439
440
 
441
442
443
444
0
@@ -89,13 +89,23 @@ ensure
0
   ENV[name] = saved
0
 end
0
 
0
+# If a command is given, this will try to execute the given command, as
0
+# described below. Otherwise, it will return a string for use in embedding in
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)
0
+def try_sudo(command=nil)
0
   as = fetch(:runner, "app")
0
   via = fetch(:run_method, :sudo)
0
-  invoke_command(command, :via => via, :as => as)
0
+  if command
0
+    invoke_command(command, :via => via, :as => as)
0
+  elsif via == :sudo
0
+    sudo(:as => as)
0
+  else
0
+    ""
0
+  end
0
 end
0
 
0
 # =========================================================================
0
@@ -131,7 +141,7 @@ namespace :deploy do
0
   task :setup, :except => { :no_release => true } do
0
     dirs = [deploy_to, releases_path, shared_path]
0
     dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
0
-    try_sudo "umask 02 && mkdir -p #{dirs.join(' ')}"
0
+    run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
0
   end
0
 
0
   desc <<-DESC
0
@@ -413,7 +423,7 @@ namespace :deploy do
0
     the :use_sudo variable to false.
0
   DESC
0
   task :start, :roles => :app do
0
-    try_sudo "sh -c 'cd #{current_path} && nohup script/spin'"
0
+    run "cd #{current_path} && #{try_sudo} nohup script/spin"
0
   end
0
 
0
   desc <<-DESC
0
@@ -428,7 +438,7 @@ namespace :deploy do
0
     the :use_sudo variable to false.
0
   DESC
0
   task :stop, :roles => :app do
0
-    try_sudo "if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi"
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
   end
0
 

Comments