Docker: Restart service unless terminated via SIGUSR1

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-03-27 21:21:34 +02:00
parent ad580a76d0
commit 8bfd95ddc4
2 changed files with 15 additions and 6 deletions

View file

@ -133,9 +133,9 @@ func startAction(ctx *cli.Context) error {
// Wait for signal to initiate server shutdown.
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
<-quit
sig := <-quit
// Stop all background activity.
auto.Stop()
@ -154,5 +154,11 @@ func startAction(ctx *cli.Context) error {
time.Sleep(2 * time.Second)
conf.Shutdown()
// Don't exit with 0 if SIGUSR1 was received to avoid restarts.
if sig == syscall.SIGUSR1 {
os.Exit(1)
return nil
}
return nil
}

View file

@ -88,6 +88,9 @@ echo "backup path...: ${PHOTOPRISM_BACKUP_PATH:-default}"
echo "import path...: ${PHOTOPRISM_IMPORT_PATH:-default}"
echo "originals path: ${PHOTOPRISM_ORIGINALS_PATH:-default}"
# error code of the last executed command
ret=0
# change to another user and group on request
if [[ ${INIT_SCRIPT} ]] && [[ $(/usr/bin/id -u) == "0" ]] && [[ ${PHOTOPRISM_UID} =~ $re ]] && [[ ${PHOTOPRISM_UID} != "0" ]]; then
# check uid and gid env variables
@ -97,14 +100,14 @@ if [[ ${INIT_SCRIPT} ]] && [[ $(/usr/bin/id -u) == "0" ]] && [[ ${PHOTOPRISM_UID
# run command as uid:gid
([[ ${DOCKER_ENV} != "prod" ]] || /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "/scripts/audit.sh") \
&& (while [ $? -eq 0 ]; do /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "$@"; done) &
&& (while /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "$@"; ret=$?; [[ $ret -eq 0 ]]; do echo "${@}"; done) &
else
echo "switching to uid ${PHOTOPRISM_UID}"
echo "${@}"
# run command as uid
([[ ${DOCKER_ENV} != "prod" ]] || /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "$(/usr/bin/id -g "${PHOTOPRISM_UID}")" --init-groups --inh-caps -all "/scripts/audit.sh") \
&& (while [ $? -eq 0 ]; do /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "$@"; done) &
&& (while /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "$@"; ret=$?; [[ $ret -eq 0 ]]; do echo "${@}"; done) &
fi
else
echo "running as uid $(id -u)"
@ -112,10 +115,10 @@ else
# run command
([[ ${DOCKER_ENV} != "prod" ]] || "/scripts/audit.sh") \
&& (while [ $? -eq 0 ]; do "$@"; done) &
&& (while "$@"; ret=$?; [[ $ret -eq 0 ]]; do echo "${@}"; done) &
fi
PID=$!
trap "kill $PID" INT TERM
trap "kill -USR1 $PID" INT TERM
wait