title: Nginx Tornado and Flask - What's a good start/stop script and keep-alive method
body: <p>I've set up a Flask application to run on a tornado server backed by nginx. I've written a couple of bash scripts to reload server configuration when a new version is deployed, but I am unhappy with them. Basically what I have is:</p>
  
  <h2>to start the server (assuming in project root)</h2>
  
  <pre><code># this starts the tornado-flask wrapper
  python myapp.py --port=8000 # .. some more misc settings
  
  # this starts nginx
  nginx
  </code></pre>
  
  <h2>to stop it</h2>
  
  <pre><code>pkill -f 'myapp.py'
  nginx -s stop
  </code></pre>
  
  <h2>to restart</h2>
  
  <pre><code>cd $APP_ROOT
  ./script/stop &amp;&amp; ./script/start
  </code></pre>
  
  <p>Many times these don't work smoothly and I need to manually run the commands. Also, I'm looking for a way to verify the service is alive, and start it up if it's down. Thoughts? Thanks.</p>