Docker: Ensure that cmd.sh terminates its child processes when the parent script closes#5172
Merged
Merged
Conversation
lastzero
reviewed
Aug 24, 2025
| #!/usr/bin/env bash | ||
|
|
||
| # clean up child processes via trap | ||
| trap 'ps -p $$ -o pgid= | xargs pgrep -A -g | xargs kill ;exit' EXIT |
Member
There was a problem hiding this comment.
Wow! That looks like kung fu! How did you come up with this? :)
Contributor
Author
There was a problem hiding this comment.
trap command from google, but the rest through trial and error.
ps $$ -o pgid= returns the group id for the current process (which is the bash script).
xargs pgrep -A -g takes the group id, and searches out all the process id's associated with it, excluding pgrep.
xargs kill takes the output from pgrep and sends a SIGTERM to them to end gracefully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
These changes improves the closing of the PhotoPrism bash command shell, so that s6 can stop PhotoPrism within the container.
The following command will stop the PhotoPrism web service, leaving the container up.
The following command will start the PhotoPrism web service, leaving the container up.
or if using Kubernetes, the following will stop the PhotoPrism web service (change the pod id to match yours):
Acceptance Criteria
Testing Evidence
Please note that testing was conducted on Kubernetes, so I haven't tested the docker commands above, which are based on https://docs.photoprism.app/getting-started/docker/#examples
The shutdown of PhotoPrism below was triggered from the kubectl command above.
The startup of PhotoPrism below was triggered from a kubectl command (the -d changed to a -u).
Prior to this fix, PhotoPrism would not shut down.