meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
git:gitlab:runner:shell [2022/01/05 18:05] – created niziakgit:gitlab:runner:shell [2022/01/24 13:25] (current) niziak
Line 22: Line 22:
   * [[https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3031|Gracefully halt cancelled jobs]]   * [[https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3031|Gracefully halt cancelled jobs]]
  
 +Solution:
 +  * Using bash wrapper script plus replace current shell with new process using ''exec''
 +<file yaml .gitlab-ci.yml>
 +build:
 +  stage: build
 +  script:
 +    - exec tools/ci/launch_job.sh make all
 +    - exec tools/ci/launch_job.sh make deploy
 +</file>
 +
 +<file bash tools/ci/launch_job.sh>
 +#!/bin/bash
 +#_term() {
 +#    echo "$0 caught SIGTERM signal!"
 +#    trap - SIGTERM
 +#    kill -TERM $child $$
 +#}
 +
 +launch_job() {
 +    PARENT=$1
 +    shift
 +    "$@" &
 +    CHILD=$!
 +    trap "trap - SIGTERM; kill -TERM $CHILD $$" SIGTERM
 +
 +    while sleep 1; do
 + if [ ! -e /proc/$PARENT ]; then 
 +     echo "Parent PID $PARENT disappears, terminating child $CHILD"
 +     kill -TERM $CHILD
 +     exit
 + fi
 +
 + if [ ! -e /proc/$CHILD ]; then
 +     wait $CHILD
 +     trap - SIGTERM
 +     exit $?
 + fi
 +    done
 +}
 +
 +#trap _term SIGTERM
 +#launch_job $$ "$@" &
 +#echo "$0 Waiting for $! to finish"
 +#wait $!
 +
 +launch_job $PPID "$@"
 +</file>