From 8102f2020bc0be20e2ea1ad97cfd0bff9aa298b6 Mon Sep 17 00:00:00 2001 From: John Leonardo Date: Sun, 14 Aug 2016 00:29:30 -0700 Subject: [PATCH 1/2] changed quit() and put it in a while loop to keep trying. never give up. --- management/email_administrator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/management/email_administrator.py b/management/email_administrator.py index b16fda1d..94de3418 100755 --- a/management/email_administrator.py +++ b/management/email_administrator.py @@ -22,8 +22,8 @@ admin_addr = "administrator@" + env['PRIMARY_HOSTNAME'] content = sys.stdin.read().strip() # If there's nothing coming in, just exit. -if content == "": - sys.exit(0) +while content == "": + content = sys.stdin.read().strip() # create MIME message msg = Message() From 526d13d6c1687e1eff27dd6ccd86466452953082 Mon Sep 17 00:00:00 2001 From: John Leonardo Date: Sun, 14 Aug 2016 00:33:34 -0700 Subject: [PATCH 2/2] added wait time and brought exit back in Yeah, probably not a good idea to have a potential inf loop, limiting it to 10 attempts with 5 sec wait time --- management/email_administrator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/management/email_administrator.py b/management/email_administrator.py index 94de3418..4448d288 100755 --- a/management/email_administrator.py +++ b/management/email_administrator.py @@ -3,6 +3,7 @@ # Reads in STDIN. If the stream is not empty, mail it to the system administrator. import sys +import time import smtplib from email.message import Message @@ -21,9 +22,15 @@ admin_addr = "administrator@" + env['PRIMARY_HOSTNAME'] # Read in STDIN. content = sys.stdin.read().strip() -# If there's nothing coming in, just exit. +# Checks if content is nil. If nil, it tries again, with 5 second wait time. after 10 attempts, quits +i = 0 while content == "": content = sys.stdin.read().strip() + time.sleep(5) + i = i + 1 + if i == 10: + sys.exit(0) + # create MIME message msg = Message()