<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *unreleased*
 
+* Make deploy:setup obey the :use_sudo and :runner directives, and generalize the :use_sudo and :runner options into a try_sudo() helper method [Jamis Buck]
+
 * Make sudo helper play nicely with complex command chains [Jamis Buck]
 
 * Expand file-transfer options with new upload() and download() helpers. [Jamis Buck]</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -89,6 +89,15 @@ ensure
   ENV[name] = saved
 end
 
+# If :run_method is :sudo (or :use_sudo is true), this executes the given command
+# via +sudo+. Otherwise is uses +run+. Further, if sudo is being used and :runner
+# is set, the command will be executed as the user given by :runner.
+def try_sudo(command)
+  as = fetch(:runner, &quot;app&quot;)
+  via = fetch(:run_method, :sudo)
+  invoke_command(command, :via =&gt; via, :as =&gt; as)
+end
+
 # =========================================================================
 # These are the tasks that are available to help with deploying web apps,
 # and specifically, Rails applications. You can have cap give you a summary
@@ -122,7 +131,7 @@ namespace :deploy do
   task :setup, :except =&gt; { :no_release =&gt; true } do
     dirs = [deploy_to, releases_path, shared_path]
     dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
-    run &quot;umask 02 &amp;&amp; mkdir -p #{dirs.join(' ')}&quot;
+    try_sudo &quot;umask 02 &amp;&amp; mkdir -p #{dirs.join(' ')}&quot;
   end
 
   desc &lt;&lt;-DESC
@@ -246,9 +255,7 @@ namespace :deploy do
       set :use_sudo, false
   DESC
   task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do
-    as = fetch(:runner, &quot;app&quot;)
-    via = fetch(:run_method, :sudo)
-    invoke_command &quot;#{current_path}/script/process/reaper&quot;, :via =&gt; via, :as =&gt; as
+    try_sudo &quot;#{current_path}/script/process/reaper&quot;
   end
 
   desc &lt;&lt;-DESC
@@ -337,7 +344,7 @@ namespace :deploy do
       directories = (releases - releases.last(count)).map { |release|
         File.join(releases_path, release) }.join(&quot; &quot;)
 
-      invoke_command &quot;rm -rf #{directories}&quot;, :via =&gt; run_method
+      try_sudo &quot;rm -rf #{directories}&quot;
     end
   end
 
@@ -406,9 +413,7 @@ namespace :deploy do
     the :use_sudo variable to false.
   DESC
   task :start, :roles =&gt; :app do
-    as = fetch(:runner, &quot;app&quot;)
-    via = fetch(:run_method, :sudo)
-    invoke_command &quot;sh -c 'cd #{current_path} &amp;&amp; nohup script/spin'&quot;, :via =&gt; via, :as =&gt; as
+    try_sudo &quot;sh -c 'cd #{current_path} &amp;&amp; nohup script/spin'&quot;
   end
 
   desc &lt;&lt;-DESC
@@ -423,11 +428,8 @@ namespace :deploy do
     the :use_sudo variable to false.
   DESC
   task :stop, :roles =&gt; :app do
-    as = fetch(:runner, &quot;app&quot;)
-    via = fetch(:run_method, :sudo)
-
-    invoke_command &quot;if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi&quot;, :via =&gt; via, :as =&gt; as
-    invoke_command &quot;#{current_path}/script/process/reaper -a kill&quot;, :via =&gt; via, :as =&gt; as
+    try_sudo &quot;if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi&quot;
+    try_sudo &quot;#{current_path}/script/process/reaper -a kill&quot;
   end
 
   namespace :pending do</diff>
      <filename>lib/capistrano/recipes/deploy.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f9d2af0b24f109874951162bd3fa761c648038ab</id>
    </parent>
  </parents>
  <author>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </author>
  <url>http://github.com/jamis/capistrano/commit/552a4924284d7f74a327b163ead1fe6b992c9c60</url>
  <id>552a4924284d7f74a327b163ead1fe6b992c9c60</id>
  <committed-date>2008-04-30T21:41:39-07:00</committed-date>
  <authored-date>2008-04-30T21:41:39-07:00</authored-date>
  <message>Make deploy:setup obey the :use_sudo and :runner directives, and generalize the :use_sudo and :runner options into a try_sudo() helper method</message>
  <tree>b53a6fadcf990c0ca40ef94fa7f1b57ebd0eafed</tree>
  <committer>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </committer>
</commit>
