+ # Send mail when the server starts
+ if test "$MAILTO" != ""
+ then
+ now=`date +"%s"`
+ restarts=`expr $restarts + 1`
+
+ # send email the first time it restarts
+ if test "$last_email" = "0"
+ then
+ cat | mail -s "ERROR - $name died, restarting.." $MAILTO <<EOF
+$name has restarted unexpectedly at $now
+
+See $log_file for details. Last 20 lines are:
+
+----------------------------------------------------------------------
+`tail -n 20 $log_file`
+EOF
+ $last_email="$now"
+ restarts=0
+ else
+ # Send email only once every hour.
+ if test "$now" -gt `expr $last_email + 3600`
+ then
+ cat | mail -s "ERROR - $name died, restarting.." $MAILTO <<EOF
+$name has restarted $restarts times since last email at $last_email
+
+See $log_file for details. Last 100 lines are:
+
+----------------------------------------------------------------------
+`tail -n 100 $log_file`
+EOF
+ $last_email="$now"
+ restarts=0
+ fi
+ fi
+ fi
+