mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +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,9 +9,11 @@ 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
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
# run the helper process which keep the listener alive
|
||||
while :;
|
||||
do
|
||||
|
||||
run() {
|
||||
# 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 $*
|
||||
returnCode=$?
|
||||
@@ -21,4 +23,38 @@ do
|
||||
echo "Exiting runner..."
|
||||
exit 0
|
||||
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