mirror of
https://github.com/actions/runner.git
synced 2025-12-13 10:05:23 +00:00
run.sh installs SIGINT and SIGTERM traps to gracefully stop runner (#2233)
* run.sh installs SIGINT and SIGTERM traps to gracefully stop runner * replaced trap to force wait for child processes and to send kill to run-helper instead of Runner.Listener * run with signal handling if RUNNER_MANUALLY_TRAP_SIG is set * Update src/Misc/layoutroot/run.sh Co-authored-by: Tingluo Huang <tingluohuang@github.com> Co-authored-by: Tingluo Huang <tingluohuang@github.com>
This commit is contained in:
@@ -9,6 +9,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
|
|||||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||||
done
|
done
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
|
run() {
|
||||||
# run the helper process which keep the listener alive
|
# run the helper process which keep the listener alive
|
||||||
while :;
|
while :;
|
||||||
do
|
do
|
||||||
@@ -22,3 +24,37 @@ do
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
runWithManualTrap() {
|
||||||
|
# Set job control
|
||||||
|
set -m
|
||||||
|
|
||||||
|
trap 'kill -INT -$PID' INT TERM
|
||||||
|
|
||||||
|
# run the helper process which keep the listener alive
|
||||||
|
while :;
|
||||||
|
do
|
||||||
|
cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh
|
||||||
|
"$DIR"/run-helper.sh $* &
|
||||||
|
PID=$!
|
||||||
|
wait -f $PID
|
||||||
|
returnCode=$?
|
||||||
|
if [[ $returnCode -eq 2 ]]; then
|
||||||
|
echo "Restarting runner..."
|
||||||
|
else
|
||||||
|
echo "Exiting runner..."
|
||||||
|
# Unregister signal handling before exit
|
||||||
|
trap - INT TERM
|
||||||
|
# wait for last parts to be logged
|
||||||
|
wait $PID
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -z "$RUNNER_MANUALLY_TRAP_SIG" ]]; then
|
||||||
|
run
|
||||||
|
else
|
||||||
|
runWithManualTrap
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user