...
 
Commits (3)
......@@ -31,14 +31,14 @@ if [ "${ICINGA_BUILD_TYPE}" == "release" ] ; then
(
set -ex
cd "${BUILDDIR}/${ICINGA_BUILD_PROJECT}"
uscan --download-current-version --verbose
run-retry-timeout uscan --download-current-version --verbose
)
else
(
set -ex
#export UPSTREAM_GIT_NOUPDATE=1 UPSTREAM_GIT_NOREPO=1
#GIT_DIR=packaging/.git
UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" ./get_snapshot
UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" run-retry-timeout ./get_snapshot
mv -t "${BUILDDIR}/" ./*.version ./*.tar*
)
fi
......
......@@ -44,13 +44,13 @@ if [ "$ICINGA_BUILD_TYPE" == "release" ] ; then
(
set -ex
cd "${BUILDDIR}/SOURCES/"
spectool -g ../SPECS/*.spec
run-retry-timeout spectool -g ../SPECS/*.spec
)
else
echo "[ Creating snapshot tarball ]"
(
set -ex
UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" ./get_snapshot
UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" run-retry-timeout ./get_snapshot
mv -t "${BUILDDIR}/SOURCES/" ./*.version ./*.tar*
)
......
#!/bin/bash
declare -i retries=3
declare -i timeout=30
declare -i interval=1
declare -i delay=1
while getopts ":t:i:d:r:" option; do
case "$option" in
t) timeout=$OPTARG ;;
i) interval=$OPTARG ;;
d) delay=$OPTARG ;;
r) retries=$OPTARG ;;
*) run-timeout -h; exit 1 ;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then
echo "You need to specify a command!" >&2
run-timeout -h
exit 1
fi
((r = retries))
while ((r > 0)); do
run-timeout -t "$timeout" -i "$interval" -d "$delay" "$@" && exit 0
((r -= 1))
sleep "$delay"
done
echo "Command failed on all $retries retries!" >&2
exit 1
#!/bin/bash
#
# The Bash shell script executes a command with a time-out.
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
#
# Based on the Bash documentation example.
# Hello Chet,
# please find attached a "little easier" :-) to comprehend
# time-out example. If you find it suitable, feel free to include
# anywhere: the very same logic as in the original examples/scripts, a
# little more transparent implementation to my taste.
#
# Dmitry V Golovashkin <Dmitry.Golovashkin@sas.com>
#
# Source: http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3
scriptName="${0##*/}"
declare -i DEFAULT_TIMEOUT=9
declare -i DEFAULT_INTERVAL=1
declare -i DEFAULT_DELAY=1
# Timeout.
declare -i timeout=DEFAULT_TIMEOUT
# Interval between checks if the process is still alive.
declare -i interval=DEFAULT_INTERVAL
# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
declare -i delay=DEFAULT_DELAY
function printUsage() {
cat <<EOF
Synopsis
$scriptName [-t timeout] [-i interval] [-d delay] command
Execute a command with a time-out.
Upon time-out expiration SIGTERM (15) is sent to the process. If SIGTERM
signal is blocked, then the subsequent SIGKILL (9) terminates it.
-t timeout
Number of seconds to wait for command completion.
Default value: $DEFAULT_TIMEOUT seconds.
-i interval
Interval between checks if the process is still alive.
Positive integer, default value: $DEFAULT_INTERVAL seconds.
-d delay
Delay between posting the SIGTERM signal and destroying the
process by SIGKILL. Default value: $DEFAULT_DELAY seconds.
As of today, Bash does not support floating point arithmetic (sleep does),
therefore all delay/time values must be integers.
EOF
}
# Options.
while getopts ":t:i:d:" option; do
case "$option" in
t) timeout=$OPTARG ;;
i) interval=$OPTARG ;;
d) delay=$OPTARG ;;
*) printUsage; exit 1 ;;
esac
done
shift $((OPTIND - 1))
# $# should be at least 1 (the command to execute), however it may be strictly
# greater than 1 if the command itself has options.
if (($# == 0 || interval <= 0)); then
printUsage
exit 1
fi
# kill -0 pid Exit code indicates if a signal may be sent to $pid process.
(
((t = timeout))
while ((t > 0)); do
sleep "$interval"
kill -0 $$ || exit 0
((t -= interval))
done
# Be nice, post SIGTERM first.
# The 'exit 0' below will be executed if any preceeding command fails.
kill -s SIGTERM $$
sleep "$delay"
kill -0 $$ || exit 0
kill -s SIGKILL $$
) 2> /dev/null &
exec "$@"