title: Docker container running supervisor shuts down too early
body: <p>I am running a docker container with multiple processes (to achieve a LAMP environment) by using supervisor as described <a href="https://docs.docker.com/articles/using_supervisord/" rel="nofollow">here</a>. Everything works fine but when I stop the container the MySQL process doesn't get properly terminated even though I've set up supervisor's pidproxy in the supervisor config</p>
  
  <pre><code>[program:mysql]
  command=/usr/bin/pidproxy /run/mysqld/mysqld.pid /bin/sh -c "exec /usr/bin/mysqld_safe"
  </code></pre>
  
  <p>When I access the container through nsenter and restart the MySQL daemon with </p>
  
  <pre><code>supervisorctl restart mysql
  </code></pre>
  
  <p>the shutdown completes without throwing an error next time it comes up. So I think supervisor is configured correctly. To me it seems docker (I am running 1.2.0) terminates the container just a bit early while mysqld is still shutting down.</p>
  
  <h2>Edit</h2>
  
  <p>I was able to debug some more details by running <code>supervisord</code> with the <code>-e debug</code> switch.</p>
  
  <p>Shutdown with <code>supervisorctl restart mysql</code> via nsenter:</p>
  
  <pre><code>DEBG fd 17 closed, stopped monitoring &lt;POutputDispatcher at 39322256 for &lt;Subprocess at 38373280 with name mysql in state RUNNING&gt; (stderr)&gt;
  DEBG fd 14 closed, stopped monitoring &lt;POutputDispatcher at 39324128 for &lt;Subprocess at 38373280 with name mysql in state RUNNING&gt; (stdout)&gt;
  DEBG killing mysql (pid 1128) with signal SIGTERM
  INFO stopped: mysql (exit status 0)
  DEBG received SIGCLD indicating a child quit
  CRIT reaped unknown pid 1129)
  DEBG received SIGCLD indicating a child quit
  </code></pre>
  
  <p>And externally via <code>docker restart container_name</code>:</p>
  
  <pre><code>DEBG fd 17 closed, stopped monitoring &lt;POutputDispatcher at 39290136 for &lt;Subprocess at 38373280 with name mysql in state RUNNING&gt; (stderr)&gt;
  DEBG fd 14 closed, stopped monitoring &lt;POutputDispatcher at 39290424 for &lt;Subprocess at 38373280 with name mysql in state RUNNING&gt; (stdout)&gt;
  DEBG killing mysql (pid 7871) with signal SIGTERM
  INFO stopped: mysql (exit status 0)
  DEBG received SIGCLD indicating a child quit
  </code></pre>
  
  <p>This is the process structure before the first attempt:</p>
  
  <pre><code> 1128 S      0:00 /usr/bin/python /usr/bin/pidproxy /run/mysqld/mysqld.pid /usr/bin/mysqld_safe
   1129 S      0:00  \_ /bin/sh /usr/bin/mysqld_safe
   1463 Sl     0:00      \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-erro
  </code></pre>
  
  <p>So while <code>pid 1463</code> gets properly reaped as it's in <code>/run/mysqld/mysqld.pid</code>, <code>pid 1129</code> causes the trouble as docker shuts down the container before it's gone. Is it a bug in supervisor's pidproxy or can it be fixed by a different configuration?</p>