diff options
Diffstat (limited to 'sup')
-rwxr-xr-x | sup | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -1,20 +1,44 @@ #!/bin/sh +# delay starting after 2 failed runs +delay_after=2 +# reset delay counter after 60 seconds +delay_reset_after=60 +# delay for 30 seconds +delay=30 + command="$*" +times_ran=0 cleanup() { - echo "killed... $pid" - kill $pid + if [ -n "$pid" ]; then + echo "killed... $pid" + kill $pid + fi exit } trap cleanup 2 15 while :; do + times_ran=$(($times_ran+1)) + if [ $times_ran -gt $delay_after ]; then + echo "sleeping for after $(($times_ran-1)) runs in $delay_reset_after seconds" + sleep $delay + fi + + time_started=`date +%s` echo -n "running... " + $command & pid=$! echo PID: $pid wait $pid + pid="" + + # reset counter if run long enough + if [ $(($time_started+$delay_reset_after)) -lt `date +%s` ]; then + times_ran=0 + fi done |