Send message via smtp to superlance using crashmail

I am trying to set up email sending when a process changes state in supervisord using crashmail . Unlucky with the sendmail program, which requires quite a lot of settings, I decided to go with a small script in Python that sends email using SMTP.

This worked very well (I received an email saying that the state of the process is changing) for the first state change, but stops working later. I tried changing various parameters in supervisord , for example buffer_size or autorestart , but it has no effect.

Here is the script that I use to trigger 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 a script that sends email through Gmail. This will send 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 

Can anyone understand why? Thanks!

+5
source share
1 answer

I moved the eventlistener section to a separate file in /etc/supervisor/conf.d (instead of ending supervisord.conf ) and now everything works as expected ...

+2
source

Source: https://habr.com/ru/post/1244242/


All Articles