krallin / tini

A tiny but valid `init` for containers
MIT License
9.87k stars 506 forks source link

tini childs dont't receive sigterm after docker stop #229

Open ardenisov opened 3 weeks ago

ardenisov commented 3 weeks ago

Hello! I have several ZEBRA daemons running in docker container with tini as entrypoint. The problem is that all zebra daemons receive SIGKILL when container stopped..

ZEBRA processes in docker container for example:

ps -a
PID   USER     TIME  COMMAND
    1 root      0:00 /sbin/tini -vvv -- /usr/lib/frr/docker-start
    7 root      0:00 {docker-start} /bin/bash /usr/lib/frr/docker-start
   11 root      0:00 /usr/lib/frr/watchfrr zebra mgmtd bgpd staticd bfdd
   27 frr       0:01 /usr/lib/frr/zebra -d -F traditional -A 127.0.0.1 -s 90000000 -M dplane_fpm_nl
   33 frr       0:00 /usr/lib/frr/mgmtd -d -F traditional
   35 frr       0:00 /usr/lib/frr/bgpd -d -F traditional -A 127.0.0.1
   42 frr       0:00 /usr/lib/frr/staticd -d -F traditional -A 127.0.0.1
   45 frr       0:02 /usr/lib/frr/bfdd -d -F traditional -A 127.0.0.1

All ZEBRA daemons have parent pid of tini (1):

cat /proc/27/status | grep PPid
PPid:   1
cat /proc/33/status | grep PPid
PPid:   1
cat /proc/35/status | grep PPid
PPid:   1
cat /proc/42/status | grep PPid
PPid:   1
cat /proc/45/status | grep PPid
PPid:   1

Another look to tini children:

pgrep -lP 1
7 /bin/bash
27 /usr/lib/frr/zebra
33 /usr/lib/frr/mgmtd
35 /usr/lib/frr/bgpd
42 /usr/lib/frr/staticd
45 /usr/lib/frr/bfdd

but only one process receive sigterm in tini logs

[DEBUG tini (1)] Passing signal: 'Terminated'
[TRACE tini (1)] No child to reap
[DEBUG tini (1)] Received SIGCHLD
[DEBUG tini (1)] Reaped child with pid: '7'
[INFO  tini (1)] Main child exited with signal (with signal 'Terminated')
[TRACE tini (1)] No child to reap
[TRACE tini (1)] Exiting: child has exited

I expect that all tini children must receive SIGTERM not only PID 7.

krallin commented 3 weeks ago

Try using process group mode (-g)

Without this flag tini doesn’t signal anything besides its first child.

You’d have to make sure your children are all in the same process group for this to work. If you need something more fancy that isn’t supported in Tini.

Hope this helps!

On Mon, 30 Sep 2024 at 11:31, ardenisov @.***> wrote:

Hello! I have several ZEBRA daemons running in docker container with tini as entrypoint. The problem is that all zebra daemons receive SIGKILL when container stopped..

ZEBRA processes in docker container for example:

ps -a PID USER TIME COMMAND 1 root 0:00 /sbin/tini -vvv -- /usr/lib/frr/docker-start 7 root 0:00 {docker-start} /bin/bash /usr/lib/frr/docker-start 11 root 0:00 /usr/lib/frr/watchfrr zebra mgmtd bgpd staticd bfdd 27 frr 0:01 /usr/lib/frr/zebra -d -F traditional -A 127.0.0.1 -s 90000000 -M dplane_fpm_nl 33 frr 0:00 /usr/lib/frr/mgmtd -d -F traditional 35 frr 0:00 /usr/lib/frr/bgpd -d -F traditional -A 127.0.0.1 42 frr 0:00 /usr/lib/frr/staticd -d -F traditional -A 127.0.0.1 45 frr 0:02 /usr/lib/frr/bfdd -d -F traditional -A 127.0.0.1

All ZEBRA daemons have parent pid of tini (1):

cat /proc/27/status | grep PPid PPid: 1 cat /proc/33/status | grep PPid PPid: 1 cat /proc/35/status | grep PPid PPid: 1 cat /proc/42/status | grep PPid PPid: 1 cat /proc/45/status | grep PPid PPid: 1

Another look to tini children:

pgrep -lP 1 7 /bin/bash 27 /usr/lib/frr/zebra 33 /usr/lib/frr/mgmtd 35 /usr/lib/frr/bgpd 42 /usr/lib/frr/staticd 45 /usr/lib/frr/bfdd

but only one process receive sigterm in tini logs

[DEBUG tini (1)] Passing signal: 'Terminated' [TRACE tini (1)] No child to reap [DEBUG tini (1)] Received SIGCHLD [DEBUG tini (1)] Reaped child with pid: '7' [INFO tini (1)] Main child exited with signal (with signal 'Terminated') [TRACE tini (1)] No child to reap [TRACE tini (1)] Exiting: child has exited

I expect that all tini children must receive SIGTERM not only PID 7.

— Reply to this email directly, view it on GitHub https://github.com/krallin/tini/issues/229, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANIHVTN5ZS4CYGR42QF7XLZZEK6XAVCNFSM6AAAAABPC3NWRGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGU2TMMBYHE2DCMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>