How is this Docker service called?

I am studying the Crunchy Postgres implementation to understand how it works.

The Dockerfile at this link runs this script as a service which remains running until the service receives a kill signal.

Can someone please explain each of the circumstances in which the script is called?

Obviously, the script is run when the container is initialized. Under this scenario, the PG_MODE environment variable is set to equal set because that is the default setting in the kubernetes statefulset code at this link.

However, the code contains a block of conditional logic for PG_MODE=replica located above the first PG_MODE=set conditional block. This indicates that can be called at times during which the PG_MODE variable has already been changed to differ from the set value defined in the Kubernetes code.

So what are the situations under which the script/service can be called? And where in the open source github code can I find the code that would trigger at a time other than startup?