I'm trying to set up the email sending when a process changes state in supervisord by using crashmail. Having no luck with the default sendmail
program which requires quite a lot of setup, I decided to go with a small script in Python that sends email using SMTP.
This worked very well (I received indeed an email saying that the process state changes) for the first state change but stop working afterward. I have tried to change different options in supervisord
such as buffer_size
or autorestart
but it has no effect.
Here is the script I use to trigger the supervisord
state changes:
import time
from datetime import datetime
if __name__ == '__main__':
print(">>>>> STARTING ...", flush=True)
while True:
print("sleep now:", datetime.utcnow(), flush=True)
time.sleep(30)
raise Exception("meo meo")
This is the script that sends email through Gmail. This one will send the stdin
.
#!/usr/bin/env python
import smtplib
def get_server():
smtpserver = smtplib.SMTP('smtp.gmail.com:587')
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login("user@gmail.com", "password")
return smtpserver
if __name__ == '__main__':
import sys
data = sys.stdin.read()
s = get_server()
s.sendmail('from@gmail.com', ['myemail@fitle.com'], data)
s.quit()
Here is my supervisord.conf
[eventlistener:crashmail]
command=crashmail -a -m myemail@gmail.com -s /home/ubuntu/mysendmail.py
events=PROCESS_STATE
buffer_size=102400
autorestart=true
Does anyone have any idea why? Thanks!