also monitor docker daemon process when using dind-rootless

This commit is contained in:
sebthom 2023-06-03 12:40:04 +02:00
parent 70913f84ad
commit c45c9fc54b
1 changed files with 32 additions and 28 deletions

View File

@ -120,39 +120,43 @@ unset $(env | grep "^GITEA_" | cut -d= -f1)
# run the act runner # run the act runner
################################################# #################################################
case $DOCKER_MODE in case $DOCKER_MODE in
dind) dind*)
act_runner daemon --config "$effective_config_file" & act_runner daemon --config "$effective_config_file" &
act_runner_pid=$! act_runner_pid=$!
function shutdown_act() { function shutdown_act() {
log INFO "Stopping act_runner..." log INFO "Stopping act_runner..."
kill -SIGTERM $act_runner_pid || true kill -SIGTERM $act_runner_pid || true
} }
function shutdown_docker() { function shutdown_docker() {
log INFO "Stopping docker engine..." log INFO "Stopping docker engine..."
sudo service docker stop if [[ $DOCKER_MODE == "dind-rootless" ]]; then
while [[ -e /proc/$DOCKER_PID ]]; do kill -SIGTERM $DOCKER_PID
log INFO "Waiting for docker engine to shutdown..." else
sleep 2 sudo service docker stop
done fi
} while [[ -e /proc/$DOCKER_PID ]]; do
log INFO "Waiting for docker engine to shutdown..."
sleep 2
done
}
trap "shutdown_act; shutdown_docker" INT TERM HUP QUIT trap "shutdown_act; shutdown_docker" INT TERM HUP QUIT
# monitoring docker engine/act_runner process status # monitoring docker engine/act_runner process status
while [[ -e /proc/$DOCKER_PID && -e /proc/$act_runner_pid ]]; do while [[ -e /proc/$DOCKER_PID && -e /proc/$act_runner_pid ]]; do
sleep 1 sleep 1
done done
if [[ -e /proc/$DOCKER_PID ]]; then if [[ -e /proc/$DOCKER_PID ]]; then
shutdown_docker shutdown_docker
else else
log ERROR "Docker engine unexpectly ended." log ERROR "Docker engine unexpectly ended."
shutdown_act shutdown_act
fi fi
exit 1 # there is no scenario where the background processes should exit on their own exit 1 # there is no scenario where the background processes should exit on their own
;; ;;
*) *)
exec act_runner daemon --config "$effective_config_file" exec act_runner daemon --config "$effective_config_file"