2019-10-10 00:52:42 -04:00
#!/bin/bash
# Change directory to the script root directory
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
2022-02-02 11:16:01 +01:00
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
[ [ $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
2019-10-10 00:52:42 -04:00
done
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2022-11-02 14:28:14 +01:00
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 = $?
if [ [ $returnCode -eq 2 ] ] ; then
echo "Restarting runner..."
else
echo "Exiting runner..."
exit 0
fi
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
2022-11-28 17:33:01 +01:00
exit $returnCode
2022-11-02 14:28:14 +01:00
fi
done
}
if [ [ -z " $RUNNER_MANUALLY_TRAP_SIG " ] ] ; then
2022-11-02 18:13:40 -04:00
run $*
2022-11-02 14:28:14 +01:00
else
2022-11-02 18:13:40 -04:00
runWithManualTrap $*
2022-11-02 14:28:14 +01:00
fi