diff options
author | Florian Pritz <bluewind@server-speed.net> | 2011-06-02 19:43:04 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@server-speed.net> | 2011-06-02 19:43:04 +0200 |
commit | 222b5ec126088ba9afed281f58a885ef9ce89093 (patch) | |
tree | 3a9e0d9ccbccfc490d0da0e15bbaf48a5badf577 /sup | |
parent | 810395db5953543e0b829a73c47c85d4447791ac (diff) | |
download | bin-222b5ec126088ba9afed281f58a885ef9ce89093.tar.gz bin-222b5ec126088ba9afed281f58a885ef9ce89093.tar.xz |
sup: delay runs if commands exits too fast
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
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 |