From 6710bbeb7c8bdcec45b1fb01c78618f6c9482e80 Mon Sep 17 00:00:00 2001
From: Jeffrey Zhang <jeffrey.zhang@99cloud.net>
Date: Thu, 18 Aug 2016 16:42:02 +0800
Subject: [PATCH] Use dumb-init to manage the pid 1 process

Normally, when you launch a Docker container, the process you're
executing becomes PID 1, giving it the quirks and responsibilities that
come with being the init system for the container.

There are two common issues this presents:

* In most cases, signals won't be handled properly.
* Orphaned zombie processes aren't properly reaped.

the dumb-init acting like a simple init system. It launches a single
process and then proxies all received signals to a session rooted at
that child process.

Closes-Bug: #1614509
Change-Id: I9d3d04648e151ddc7c6732b92ffd3b6c9fe467ec
---
 docker/base/Dockerfile.j2                                     | 4 +++-
 docker/base/start.sh                                          | 2 +-
 docker/kolla-toolbox/Dockerfile.j2                            | 2 +-
 .../add-dumb-init-manage-root-process-e25a529b322d4fac.yaml   | 3 +++
 4 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 releasenotes/notes/add-dumb-init-manage-root-process-e25a529b322d4fac.yaml

diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2
index 22a6278f4c..49700bc4b3 100644
--- a/docker/base/Dockerfile.j2
+++ b/docker/base/Dockerfile.j2
@@ -262,6 +262,8 @@ RUN touch /usr/local/bin/kolla_extend_start \
     && chmod 755 /usr/local/bin/kolla_start /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_set_configs \
     && chmod 440 /etc/sudoers \
     && groupadd kolla \
-    && rm -f /tmp/kolla_bashrc
+    && rm -f /tmp/kolla_bashrc \
+    && curl -sSL https://github.com/Yelp/dumb-init/releases/download/v1.1.3/dumb-init_1.1.3_amd64 -o /usr/local/bin/dumb-init \
+    && chmod +x /usr/local/bin/dumb-init
 
 CMD ["kolla_start"]
diff --git a/docker/base/start.sh b/docker/base/start.sh
index b45660bd8f..c1dfe68cc4 100644
--- a/docker/base/start.sh
+++ b/docker/base/start.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/local/bin/dumb-init /bin/bash
 set -o errexit
 
 # Wait for the log socket
diff --git a/docker/kolla-toolbox/Dockerfile.j2 b/docker/kolla-toolbox/Dockerfile.j2
index 44611c059a..8e12bfce9a 100644
--- a/docker/kolla-toolbox/Dockerfile.j2
+++ b/docker/kolla-toolbox/Dockerfile.j2
@@ -66,7 +66,7 @@ COPY ansible.cfg /home/ansible/.ansible.cfg
 COPY ansible_sudoers /etc/sudoers.d/ansible_sudoers
 RUN chmod 440 /etc/sudoers.d/ansible_sudoers
 
-CMD ["/bin/sleep", "infinity"]
+CMD ["/usr/local/bin/dumb-init", "/bin/sleep", "infinity"]
 
 {% block kolla_toolbox_footer %}{% endblock %}
 {% block footer %}{% endblock %}
diff --git a/releasenotes/notes/add-dumb-init-manage-root-process-e25a529b322d4fac.yaml b/releasenotes/notes/add-dumb-init-manage-root-process-e25a529b322d4fac.yaml
new file mode 100644
index 0000000000..cc8854fd8b
--- /dev/null
+++ b/releasenotes/notes/add-dumb-init-manage-root-process-e25a529b322d4fac.yaml
@@ -0,0 +1,3 @@
+---
+features:
+  - use dumb-init to manage the pid 1 process