1

My Dockerfile looks like this:

FROM ubuntu:latest
# ... there is more
ENTRYPOINT ["/root/startup.sh"]
CMD ["choose_random"]

So startup.sh is called with a default paramater if none is provided by the user.

My startup.sh is this one:

#!/bin/bash

# init database etc.
python3 /root/boot.py $1
# snmpd
/usr/sbin/snmpd -f -Lo &
# logger
tail -f /var/log/mylog.log

Now I want to simply call cleanup.py whenever a SIGTERM is received. I saw a few examples but my knowledge about the bash syntax is too little to actually understand and transfer onto my situation. I understand that I need a SIGTERM trap, but how do I actually call the cleanup script a wait until it's finished?

Thanks in advance! Markus

Standard
  • 1,450
  • 17
  • 35

1 Answers1

1

Have you tried this method?

If it works, you can just change what's inside the function to call your cleanup script.

  • Sorry I already closed the question, but it works only when I'm stoping the script with Ctrl+C. When stop the container from outside, it doesn't call the handler. Do you have any idea why? – Standard Nov 27 '20 at 07:51