Does runit reap orphan processes?

I am writing a small Docker container based on Phusion baseimage which provides runit out of the box.

I put Cassandra and Opscenter agent in my container. Both are started as service under /etc/service (as in the doc).

  • Dealing with data in Docker Containers with Gitlab-Ci
  • Pass environment variable from linux to docker container
  • Docker Network inside a container partially working
  • Exclude starting some containers with Docker Compose
  • How do I install os specific packages inside docker?
  • Installing numpy on Docker Alpine
  • This blog post mentions that my_init would collect zombie processes, but is vague about what it does with orphan processes.

    Here’s an example output of ps -ef in my Docker container:

    UID        PID  PPID  C STIME TTY          TIME CMD
    root         1     0  0 06:05 ?        00:00:00 /usr/bin/python3 -u /sbin/my_init
    root        27     1  0 06:05 ?        00:00:00 /usr/bin/runsvdir -P /etc/service
    root        28    27  0 06:05 ?        00:00:00 runsv sshd
    root        29    27  0 06:05 ?        00:00:00 runsv syslog-ng
    root        30    27  0 06:05 ?        00:00:00 runsv cron
    root        31    27  0 06:05 ?        00:00:00 runsv cassandra
    root        32    27  0 06:05 ?        00:00:00 runsv syslog-forwarder
    root        33    27  0 06:05 ?        00:00:00 runsv opscenter-agent
    root        34    32  0 06:05 ?        00:00:00 tail -F -n 0 /var/log/syslog
    root        35    30  0 06:05 ?        00:00:00 /usr/sbin/cron -f
    root        36    29  0 06:05 ?        00:00:00 syslog-ng -F -p /var/run/syslog-ng.pid --no-caps
    root        37    31 43 06:05 ?        00:00:10 java -ea -javaagent:/usr/share/cassandra/lib/jamm-0.3.0.jar -XX:+CMSClassUnloadingEnabled -XX:+UseThreadPriorities -XX:ThreadPrio
    root        38    33  0 06:05 ?        00:00:00 /bin/bash /usr/local/opscenter/datastax-agent-5.2.0/bin/datastax-agent -f
    root       471    38 51 06:05 ?        00:00:11 /usr/lib/jvm/jre1.8.0_51/bin/java -Dagent-foreground=yes -Xmx128M -Djclouds.mpu.parts.magnitude=100000 -Djclouds.mpu.parts.size=1
    root       494     0  0 06:05 ?        00:00:00 bash
    root       761   494  0 06:05 ?        00:00:00 ps -ef
    

    Note runsv opscenter-agent (pid 33) starts a child process which is a bash call (pid 38) with a child process (pid 471).

    Then I ran sv stop opscenter-agent, and ps -ef:

    UID        PID  PPID  C STIME TTY          TIME CMD
    root         1     0  0 06:05 ?        00:00:00 /usr/bin/python3 -u /sbin/my_init
    root        27     1  0 06:05 ?        00:00:00 /usr/bin/runsvdir -P /etc/service
    root        28    27  0 06:05 ?        00:00:00 runsv sshd
    root        29    27  0 06:05 ?        00:00:00 runsv syslog-ng
    root        30    27  0 06:05 ?        00:00:00 runsv cron
    root        31    27  0 06:05 ?        00:00:00 runsv cassandra
    root        32    27  0 06:05 ?        00:00:00 runsv syslog-forwarder
    root        33    27  0 06:05 ?        00:00:00 runsv opscenter-agent
    root        34    32  0 06:05 ?        00:00:00 tail -F -n 0 /var/log/syslog
    root        35    30  0 06:05 ?        00:00:00 /usr/sbin/cron -f
    root        36    29  0 06:05 ?        00:00:00 syslog-ng -F -p /var/run/syslog-ng.pid --no-caps
    root        37    31 19 06:05 ?        00:00:11 java -ea -javaagent:/usr/share/cassandra/lib/jamm-0.3.0.jar -XX:+CMSClassUnloadingEnabled -XX:+UseThreadPriorities -XX:ThreadPrio
    root       471     1 20 06:05 ?        00:00:11 /usr/lib/jvm/jre1.8.0_51/bin/java -Dagent-foreground=yes -Xmx128M -Djclouds.mpu.parts.magnitude=100000 -Djclouds.mpu.parts.size=1
    root       494     0  0 06:05 ?        00:00:00 bash
    root       768   494  0 06:06 ?        00:00:00 ps -ef
    

    Note pid 38 is gone, but pid 471 is now attached to my_init.

    Is this the correct behavior? What should I do to reap the child process?

  • How to restart container using container-id?
  • Docker volumes mount binding permissions difference between maven build and docker cli
  • DataStax Docker problems with stoping nodes
  • exporting DOCKER_HOST in .bashrc produces a different result to the same command in the terminal
  • Inconsistent runtime kernel parameters in DOCKER container and on host
  • Run shell script inside Docker container from another Docker container?
  • One Solution collect form web for “Does runit reap orphan processes?”

    my_init adopts orphaned processes and reaps them. But you misunderstood what “reaping” means. my_init does not tell it to exit; my_init only waits until it exits. You (or the process) are still responsible for making sure that it exits.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.