title: How to start Zookeeper and then Kafka?
body: <p>I'm getting started with <a href="http://docs.confluent.io/3.1.1/quickstart.html#quickstart" rel="nofollow noreferrer">Confluent Platform</a> which requires to run Zookeeper (<code>zookeeper-server-start /etc/kafka/zookeeper.properties</code>) and then Kafka (<code>kafka-server-start /etc/kafka/server.properties</code>). I am writing an Upstart script that should run both Kafka and Zookeeper. The issue is that Kafka should block until Zookeeper is ready (because it depends on it) but I can't find a reliable way to know when Zookeeper is ready. Here are some attempts in pseudo-code after running the Zookeeper server start:</p>
  
  <ol>
  <li><p>Use a hardcoded block</p>
  
  <pre><code>sleep 5   
  </code></pre>
  
  <p>Does not work reliably on slower computers and/or waits longer than needed.</p></li>
  <li><p>Check when something (hopefully Zookeeper) is running on port 2181</p>
  
  <pre><code>wait until $(echo stat | nc localhost ${port}) is not none
  </code></pre>
  
  <p>This did not seem to work as it doesn't wait long enough for Zookeeper to accept a Kafka connection.</p></li>
  <li><p>Check the logs</p>
  
  <pre><code> wait until specific string in zookeeper log is found
  </code></pre>
  
  <p>This is sketchy and there isn't even a string that cannot also be found on error too (e.g. "binding to port [...]").</p></li>
  </ol>
  
  <p>Is there a reliable way to know when Zookeeper is ready to accept a Kafka connection? Otherwise, I will have to resort to a combination of 1 and 2.</p>