I am facing a strange behavior in my Bash
script, I have this Bash
script which is running with PID 1
(it is an entrypoint
for Docker
container, if you are not familiar with Docker, I assume you can ignore this info).
When I run the following script, SIGTERM
terminates everything very quickly, and everything seems to be fine (please keep in mind that sshd
service does not exist! My whole system starts only this script which runs tail
nothing more, but till now it is not the problem).
#!/bin/bash
trap "pkill sshd" SIGTERM
export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
if [ -f /usr/local/samba/etc/smb.conf ]; then
exec /usr/local/samba/sbin/samba -i
else
tail -f /dev/null & wait ${!}
fi
The problem comes when I delete that trap
. Now my system hangs, and it seems because tail is still running and does not end for some reason (if you are familiar with Docker, Docker waits for 10 seconds, and then kill the container, because it didn't respond for the SIGTERM
, again if you are not familiar with Docker, ignore this info).
#!/bin/bash
export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
if [ -f /usr/local/samba/etc/smb.conf ]; then
exec /usr/local/samba/sbin/samba -i
else
tail -f /dev/null & wait ${!}
fi
Could someone explain to me what is the problem exactly? Why does that fake trap
makes everything to work (although it does practically nothing, but it works because it is simply there).
I just still want to mention that using an empty trap
: trap "" SIGTERM
doesn't help, something should be there in the trap to work (even if it does nothing).
Hope that someone can help me, thanks!