From 222b5ec126088ba9afed281f58a885ef9ce89093 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 2 Jun 2011 19:43:04 +0200 Subject: sup: delay runs if commands exits too fast Signed-off-by: Florian Pritz --- sup | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/sup b/sup index 9fad081..d2d84eb 100755 --- a/sup +++ b/sup @@ -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 -- cgit v1.2.3-24-g4f1b