6

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!

Son
  • 1,835
  • 2
  • 18
  • 28

1 Answers1

2

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 ...

Son
  • 1,835
  • 2
  • 18
  • 28
  • Thats strange, any idea why it needed to be in a separate file like that? I'm needing to implement a very similar solution i'll probably use ruby however – wired00 Mar 31 '16 at 04:46
  • not working for me man. I am wondering how this will run if it is moved to `conf.d`. Do we need to run it separately using `supervisord`? – Indra Jul 05 '19 at 10:39