Icinga / docker-icinga2

Official Icinga 2 Docker images
GNU General Public License v2.0
66 stars 30 forks source link

Let dumb-init reap zombie processes #38

Closed Al2Klimov closed 3 years ago

Al2Klimov commented 3 years ago

fixes #34

Al2Klimov commented 3 years ago

Before

➜  docker-icinga2 git:(master) cat dumbinit/etc/icinga2/conf.d/my.conf
object CheckCommand "zombie" {
    command = [ "bash", "-c", "sleep 5 </dev/null >/dev/null 2>&1 &" ]
}

object Host "zombie" {
    check_command = "zombie"
    check_interval = 1s
}
➜  docker-icinga2 git:(master) docker run --name dumbinit --rm -dv $(pwd)/dumbinit:/data icinga/icinga2

e8ea8f13f6d95a3f3e6c08bfc25176da0d1132e37c10b099a471d2f74dc2b019
➜  docker-icinga2 git:(master) docker exec -it dumbinit ps -efH
UID        PID  PPID  C STIME TTY          TIME CMD
icinga     127     0  0 12:45 pts/0    00:00:00 ps -efH
icinga       1     0  3 12:45 ?        00:00:00 /usr/lib/x86_64-linux-gnu/icinga
icinga      43     1  1 12:45 ?        00:00:00   /usr/lib/x86_64-linux-gnu/icin
icinga      52    43  0 12:45 ?        00:00:00     /usr/lib/x86_64-linux-gnu/ic
icinga      78     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      80     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      82     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      84     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      86     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      88     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      90     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      92     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      94     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      96     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga      98     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga     101     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga     103     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga     111     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga     113     1  0 12:45 ?        00:00:00   [sleep] <defunct>
icinga     115     1  0 12:45 ?        00:00:00   sleep 5
icinga     119     1  0 12:45 ?        00:00:00   sleep 5
icinga     121     1  0 12:45 ?        00:00:00   sleep 5
icinga     123     1  0 12:45 ?        00:00:00   sleep 5
icinga     125     1  0 12:45 ?        00:00:00   sleep 5
➜  docker-icinga2 git:(master)

After

➜  docker-icinga2 git:(bugfix/zombie-processes-34) docker run --name dumbinit --rm -dv $(pwd)/dumbinit:/data icinga/icinga2
d829c81d11e01570d64047dad97b2403176978f93bc6a9f589c989b35df45074
➜  docker-icinga2 git:(bugfix/zombie-processes-34) docker exec -it dumbinit ps -efH
UID        PID  PPID  C STIME TTY          TIME CMD
icinga     196     0  0 12:50 pts/0    00:00:00 ps -efH
icinga       1     0  0 12:49 ?        00:00:00 dumb-init -c icinga2 daemon
icinga      13     1  2 12:49 ?        00:00:00   /usr/lib/x86_64-linux-gnu/icin
icinga      45    13  1 12:49 ?        00:00:00     /usr/lib/x86_64-linux-gnu/ic
icinga      54    45  0 12:49 ?        00:00:00       /usr/lib/x86_64-linux-gnu/
icinga     192    54  0 12:50 ?        00:00:00         /usr/lib/nagios/plugins/
icinga     193   192  0 12:50 ?        00:00:00           /bin/ping -4 -n -U -w
icinga     182     1  0 12:50 ?        00:00:00   sleep 5
icinga     185     1  0 12:50 ?        00:00:00   sleep 5
icinga     189     1  0 12:50 ?        00:00:00   sleep 5
icinga     191     1  0 12:50 ?        00:00:00   sleep 5
icinga     195     1  0 12:50 ?        00:00:00   sleep 5
➜  docker-icinga2 git:(bugfix/zombie-processes-34) docker exec -it dumbinit ps -efH
UID        PID  PPID  C STIME TTY          TIME CMD
icinga     283     0  0 12:50 pts/0    00:00:00 ps -efH
icinga       1     0  0 12:49 ?        00:00:00 dumb-init -c icinga2 daemon
icinga      13     1  1 12:49 ?        00:00:00   /usr/lib/x86_64-linux-gnu/icin
icinga      45    13  0 12:49 ?        00:00:00     /usr/lib/x86_64-linux-gnu/ic
icinga      54    45  0 12:49 ?        00:00:00       /usr/lib/x86_64-linux-gnu/
icinga     266     1  0 12:50 ?        00:00:00   sleep 5
icinga     274     1  0 12:50 ?        00:00:00   sleep 5
icinga     277     1  0 12:50 ?        00:00:00   sleep 5
icinga     279     1  0 12:50 ?        00:00:00   sleep 5
icinga     282     1  0 12:50 ?        00:00:00   sleep 5
➜  docker-icinga2 git:(bugfix/zombie-processes-34)
Al2Klimov commented 3 years ago

Would be nice to have this merged before the next release.

julianbrost commented 3 years ago

By next release you mean 2.12.2, 2.12.3 or 2.13.0?

Al2Klimov commented 3 years ago

All of them.

julianbrost commented 3 years ago

How will this interact in combination with https://github.com/Icinga/icinga2/pull/8512 (not) being merged? If that one is not merged, this should just do nothing as there are no zombie processes? So that PR is not required for this one, it would just remove stuff that's no longer needed if this one gets merged, right?

Al2Klimov commented 3 years ago

Exactly.

julianbrost commented 3 years ago

Just noticed that the dumb-init readme uses -- to separate the command, so probably we should also do this.

Al2Klimov commented 3 years ago

But the man page doesn't.

julianbrost commented 3 years ago

On using -- or not: probably doesn't make a big difference as it stops interpreting arguments after the first one that doesn't start with -:

root@6feb8a61afaf:/# dumb-init -c icinga2 --version | head -1 
icinga2 - The Icinga 2 network monitoring daemon (version: r2.12.2-1)
root@6feb8a61afaf:/# dumb-init -c -- icinga2 --version | head -1
icinga2 - The Icinga 2 network monitoring daemon (version: r2.12.2-1)

So you would only notice a difference if someonet tries to run something like --version as a command (but there the exit code will differ):

root@6feb8a61afaf:/# dumb-init -c --version
dumb-init v1.2.2
root@6feb8a61afaf:/# dumb-init -c -- --version
[dumb-init] --version: No such file or directory