defmain(): while1: write_stdout('READY\n') # transition from ACKNOWLEDGED to READY line = sys.stdin.readline() # read header line from stdin write_stderr(line) # print it out to stderr headers = dict([ x.split(':') for x in line.split() ]) data = sys.stdin.read(int(headers['len'])) # read the event payload write_stderr(data) # print the event payload to stderr write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED
# A event listener meant to be subscribed to PROCESS_STATE_CHANGE # events. It will send mail when processes that are children of # supervisord transition unexpectedly to the EXITED state.
import os import socket import sys from supervisor import childutils
if option in ('-p', '--program'): programs.append(value)
if option in ('-a', '--any'): any = True
if option in ('-s', '--sendmail_program'): sendmail = value
if option in ('-m', '--email'): email = value
if option in ('-o', '--optionalheader'): optionalheader = value
# listener 必须交由 supervisor 管理, 自己运行是不行的 ifnot'SUPERVISOR_SERVER_URL'in os.environ: sys.stderr.write('crashmail must be run as a supervisor event ' 'listener\n') sys.stderr.flush() return
## Usage doc = """\ crashmail.py [-p processname] [-a] [-o string] [-m mail_address] [-s sendmail] URL Options: -p -- specify a supervisor process_name. Send mail when this process transitions to the EXITED state unexpectedly. If this process is part of a group, it can be specified using the 'process_name:group_name' syntax. -a -- Send mail when any child of the supervisord transitions unexpectedly to the EXITED state unexpectedly. Overrides any -p parameters passed in the same crashmail process invocation. -o -- Specify a parameter used as a prefix in the mail subject header. -s -- the sendmail command to use to send email (e.g. "/usr/sbin/sendmail -t -i"). Must be a command which accepts header and message data on stdin and sends mail. Default is "/usr/sbin/sendmail -t -i". -m -- specify an email address. The script will send mail to this address when crashmail detects a process crash. If no email address is specified, email will not be sent. The -p option may be specified more than once, allowing for specification of multiple processes. Specifying -a overrides any selection of -p. A sample invocation: crashmail.py -p program1 -p group1:program2 -m dev@example.com """
坑 & 爬坑
虽然 eventlistener 在配置文件中的地位上和 program 是相同的,但是待遇那可是不一样的。在使用的过程中我就遇到了两个坑,现记录如下。
1 号坑
1 号坑属性: 如果修改修改一个 program 的配置,使用supervisorctl update即可载入最新的配置并按需重启对应的 program,在终端里的表现如下:
1 2 3 4
$ supervisorctl update TestCrashMail: stopped TestCrashMail: updated process group $Copy
$ supervisord -c /etc/supervisord.conf Error: [eventlistener:listener-crashmail] section sets redirect_stderr=true but this is not allowed because it will interfere with the eventlistener protocol For help, use /usr/local/bin/supervisord -hCopy