title: How can I make capistrano wait for a service to start up on all servers before continuing?
body: <p>We do our deployments with capistrano. Our website consists of a rails frontend and java API backend.</p>
  
  <p>I have a situation where the java API application takes about 15 minutes to start up and the rails application can't run without it. Initially I tried to loop within capistrano using the capture command to wait until the application started listening on the port (8080 in our case):</p>
  
  <pre><code>desc "Start api"
  task :api, :roles =&gt; :api do
    run("cd #{home_api} &amp;&amp; ./api.sh start &gt; /dev/null 2&gt;&amp;1 &amp;")
    sleep 1
    api_status = nil
    until api_status
      api_status = capture("echo `netstat -tln | grep 8080`")
      sleep 60
    end
    puts "API Started successfully."
  end
  </code></pre>
  
  <p>However, <a href="https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Inspection-Capture" rel="nofollow">capture only runs on one server</a> (we have several API machines) and if that one finishes starting up before the others the deployment may proceed before all the API machines are ready.</p>
  
  <p>I need something that will wait for a port to be open on all servers matching the specified role before moving on.</p>