Docker entrypoint.sh for self-updating programs

I want to run a (java) application in a docker container. This application has an update functionality. This is run automatically on startup and can be triggered manually from the (web) GUI. The update downloads the new files, then runs the new executable (with new PID) and exits itself.

Usually, I use the exec java -jar MyProgram.jar "[email protected]" in entrypoint.sh. This will stop the container when an update occurs (because PID=1 exits).

Just using the line without exec does not correctly forward SIGTERM/SIGKILL for docker stop. While forwarding these signals is possible as explaned here in program.sh, I don’t know how to track PIDs when an update occurs.

Update: Since I am not the developer of the application, I am looking for a solution without modifying the applications.

Source: StackOverflow