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).
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?
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.