Graceful Shutdown of process when ran from entrypoint script

Long story short, I have some base images that don’t call the service its running directly in the ENTRYPOINT command.

Instead, I made custom .ps1 scripts (to execute commands that must be done at container/service runtime) before finishing with a direct call to the application. (Sometimes even a call to start a windows service and wait until it’s in a stopped status.)

Since these commands are executed in a powershell script, I am wondering how the actual applications get shutdown, when for example a service replica/container fails a healthcheck and needs to be recreated.

It is my understanding that even if I run a given process in the foreground from my powershell entrypoint, powershell will not ‘forward’ the appropriate signal to the actual process, but instead kill it forcefully. I ask because I do not want to corrupt any persistent data services may be writing to when they fail a healthcheck. The biggest one to worry about being a database service.

Am I misunderstanding the innerworkings of containers here? Do I need to handle this in my entrypoint ps1 scripts? Basically, how can I ensure my database process called from an entrypoint script gracefully shuts down when the orchestrator deems it unhealthy? Do I need to rethink my approach to entrypoint scripts? Any help is appreciated

It seems that Docker Windows containers send the shutdown signal to all processes in the container, so the actual service process should be shutting down gracefully (provided it has enough time). It is also my understanding that passing in a timeout value from docker does not function properly, and this grace period is defined by a registry entry. See:
(Unable to react to graceful shutdown of (Windows) container · Issue #25982 · moby/moby · GitHub)
(Provide an easy way to send graceful shutdown signal to all processes in a Windows container · Issue #124664 · kubernetes/kubernetes · GitHub)

This has been solved - see this comment thread for steps: Automatic Gracefull DOCKER container SHUTDOWN on SYSTEM Restart/Shutdown (SYSTEM OS) - #7 by owqc

Hope someone finds this useful