Note that there are some explanatory texts on larger screens.

plurals
  1. PONginx rolling restart of Rails app with capistrano
    text
    copied!<p>For the life of me I can't figure out how to make this work properly.</p> <p>The problem is similar to what others have, such as: <a href="https://stackoverflow.com/questions/124250/how-to-do-a-rolling-restart-of-a-cluster-of-mongrels">How to do a rolling restart of a cluster of mongrels</a></p> <p>We, however, are using Nginx/Passenger instead of Mongrel.</p> <p>The issue is that on a deploy if we use this standard :restart task:</p> <pre><code>task :restart, :roles =&gt; [:app], :except =&gt; {:no_release =&gt; true} do run "cd #{deploy_to}/current &amp;&amp; touch tmp/restart.txt" end </code></pre> <p>It touches the restart.txt file across every web server, but any passenger instances currently serving requests need to finish before the new ones are spawned it seems. This creates a serious delay and causes our app to be unavailable for up to 2 minutes while everything is coming back up.</p> <p>In order to get around that the plan is to do the following:</p> <ol> <li>deploy code</li> <li>go to server 1, remove it from the load balancer</li> <li>restart nginx-passenger on server 1</li> <li>wait 60 seconds</li> <li>add server 1 back to load balancer</li> <li>go to server 2 (repeat steps 3 - 5)</li> </ol> <p>To accomplish this, I attempted this:</p> <p>(lb.txt is the file that the load balancer looks for)</p> <pre><code>task :restart, :roles =&gt; [:app], :except =&gt; {:no_release =&gt; true} do servers = find_servers_for_task(current_task) servers.map do |s| run "cd #{deploy_to}/current &amp;&amp; echo '' &gt; public/lb.txt", :host =&gt; s.host run %Q{rvmsudo /etc/init.d/nginx-passenger restart &gt; /dev/null}, :host =&gt; s.host sleep 60 run "cd #{deploy_to}/current &amp;&amp; echo 'ok' &gt; public/lb.txt", :host =&gt; s.host end end </code></pre> <p>This <em>almost</em> works, however, during the deploy it seemed to run the loop through the servers once per servers listed in the :app role. We currently have 6 app servers, so the loop runs 6 times, restarting nginx-passenger 6 times per server.</p> <p>I just need this loop to run through one time.</p> <p>I know it seems that eventually passenger will get rolling restarts, but they do not seem to exist yet.</p> <p>If it helps, we are using Capistrano 2.x and Rails 3</p> <p>Any help would be great.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload