Permalink
Browse files

set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…

…nd period

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@1373 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 4e1c43f commit 6949c22b58237e6ea4167300d9285bd8ca33aab4 @vinoski vinoski committed Jan 29, 2009
Showing with 30 additions and 3 deletions.
  1. +30 −3 scripts/yaws.template
View
@@ -102,6 +102,35 @@ wait_started() {
}
+now=`date -u +%s`
+if [ "$HEART" = true ]; then
+ # we were restarted by heart, make sure we haven't reached our restart count
+ # if we get 5 restarts within 60 seconds, we exit completely
+ timediff=`expr $now - $YAWS_HEART_START`
+ if [ $timediff -le 60 ]; then
+ if [ $YAWS_HEART_RESTARTS -eq 5 ]; then
+ echo 5 restarts attempted within 60 seconds, exiting
+ exit 1
+ else
+ # we haven't reached the restart max count yet, but we're still
+ # within the 60 second window so increment the counter
+ # but keep the same start time
+ restarts=`expr $YAWS_HEART_RESTARTS + 1`
+ starttime=$YAWS_HEART_START
+ fi
+ else
+ # the previous restart was outside our 60 second window,
+ # so reset both the start time and the restart counter
+ restarts=1
+ starttime=$now
+ fi
+else
+ restarts=1
+ starttime=$now
+fi
+HEART_COMMAND="${ENV_PGM} HEART=true YAWS_HEART_RESTARTS=$restarts YAWS_HEART_START=$starttime $program "${1+"$@"}
+export HEART_COMMAND
+
while [ $# -gt 0 ]
do
arg=$1
@@ -248,9 +277,7 @@ trace="${trace} ${traceoutput}"
XEC="${daemon} ${heart} +K ${kpoll} -pa ${yawsdir}${delim}ebin ${xpath} ${sname} ${pdist} ${erlarg} ${debug} -run yaws ${trace} ${conf} ${runmod} ${mnesia} ${id}"
if [ -z "$heart" ] || [ -z "$daemon" ]; then
- HEART_COMMAND="";
-else
- export HEART_COMMAND="${ENV_PGM} HEART=true \"$erl\" $XEC";
+ unset HEART_COMMAND
fi
${RUN_ERL} "exec $erl $XEC"

0 comments on commit 6949c22

Please sign in to comment.