summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsup57
1 files changed, 54 insertions, 3 deletions
diff --git a/sup b/sup
index 3ec84f5..c6cb304 100755
--- a/sup
+++ b/sup
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# delay starting after 2 failed runs
delay_after=2
@@ -7,7 +7,6 @@ delay_reset_after=60
# delay for 30 seconds
delay=30
-command="$*"
times_ran=0
cleanup() {
@@ -21,6 +20,58 @@ cleanup() {
trap cleanup 2 15
while :; do
+ case $1 in
+ --delay)
+ if [[ ! $2 ]]; then
+ echo "Missing argument to --delay" >&2
+ exit 1
+ fi
+
+ delay=$2
+ shift 2
+ continue
+ ;;
+ --reset-after)
+ if [[ ! $2 ]]; then
+ echo "Missing argument to --reset-after" >&2
+ exit 1
+ fi
+
+ delay_reset_after=$2
+ shift 2
+ continue
+ ;;
+ --delay-after)
+ if [[ ! $2 ]]; then
+ echo "Missing argument to --delay-after" >&2
+ exit 1
+ fi
+
+ delay_after=$2
+ shift 2
+ continue
+ ;;
+ --help|-h)
+ echo "usage: ${0##*/} [options] [--] <command ...>"
+ echo ''
+ echo 'Options:'
+ echo ' --help, -h this help'
+ echo ' --delay <number> amount of delay after enoguh failed runs'
+ echo ' --delay-after <number> amount of runs after which we wait'
+ echo ' --reset-after <number> reset the failed counter after this time'
+ exit 0
+ ;;
+ --|*)
+ shift
+ break
+ ;;
+ esac
+ shift
+done
+
+command=("$@")
+
+while :; do
times_ran=$(($times_ran+1))
if [ $times_ran -gt $delay_after ]; then
echo "sleeping for $delay seconds after $(($times_ran-1)) runs in $delay_reset_after seconds" >&2
@@ -30,7 +81,7 @@ while :; do
time_started=`date +%s`
echo -n "running... " >&2
- $command &
+ ${command[@]} &
pid=$!
echo PID: $pid >&2
wait $pid