title: PID 1 for application automatically restarted in bash loop
body: <p>Given is a microservice that after some time needs to quit itself. This is no error condition but (in that case) normal behavior.
  After exiting it should be automatically restarted.</p>
  
  <p>So currently I have a script <code>run_app.sh</code>:</p>
  
  <pre><code>#!/usr/bin/env bash
  while true; do ./app ; done
  </code></pre>
  
  <p>And in the <code>Dockerfile</code> (inheriting <code>FROM ubuntu:16.04</code>) I run it like this:</p>
  
  <pre><code>CMD ["./run_app.sh"]
  </code></pre>
  
  <p>It "works" but since <code>app</code> does not have PID 1, it does not receive SIGTERM etc. coming from Kubernetes, which is needed for a graceful shutdown during rolling updates etc.</p>
  
  <p>Using <code>while true; do exec ./app ; done</code> in <code>run_app.sh</code> does not solve the problem since the loop no longer exists when <code>app</code> finished and no restart is performed.</p>
  
  <p>How can I restart the app automatically inside the container without restarting the container / pod every time it quits, but still have the advantages of PID 1?</p>