summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-06-02 19:43:04 +0200
committerFlorian Pritz <bluewind@server-speed.net>2011-06-02 19:43:04 +0200
commit222b5ec126088ba9afed281f58a885ef9ce89093 (patch)
tree3a9e0d9ccbccfc490d0da0e15bbaf48a5badf577
parent810395db5953543e0b829a73c47c85d4447791ac (diff)
downloadbin-222b5ec126088ba9afed281f58a885ef9ce89093.tar.gz
bin-222b5ec126088ba9afed281f58a885ef9ce89093.tar.xz
sup: delay runs if commands exits too fast
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
-rwxr-xr-xsup28
1 files 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