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("[email protected]", "password")
return smtpserver
if __name__ == '__main__':
import sys
data = sys.stdin.read()
s = get_server()
s.sendmail('[email protected]', ['[email protected]'], data)
s.quit()
Here is my supervisord.conf
[eventlistener:crashmail]
command=crashmail -a -m [email protected] -s /home/ubuntu/mysendmail.py
events=PROCESS_STATE
buffer_size=102400
autorestart=true
Does anyone have any idea why? Thanks!
I moved the eventlistener section to a separate file in /etc/supervisor/conf.d (instead of putting at the end of supervisord.conf) and now everything is working as expected ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With