我正在尝试为supervisord配置一个事件监听器,但无法让它工作。 我只是想监听PROCESS_STATE更改并运行一些python代码来触发urllib2request。
在我的.conf中我有:
[eventlistener:statechanges]
command=python listener.py
events=PROCESS_STATE
在listener.py中:
def run():
runFunc() # Function to trigger an urllib2request
if __name__ == '__main__':
run()
然后触发器不会启动,只是在重试后才进入FATAL状态。
statechanges entered FATAL state, too many start retries too quickly
任何想法或有人都有一个如何为supervisord编写监听器的例子吗?
答案 0 :(得分:5)
你不能只打印随机字符串,supervisord在stdout上监听:)
来自文档的这个例子怎么样:
import sys
def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while 1:
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
if __name__ == '__main__':
main()
import sys
http://supervisord.org/events.html#example-event-listener-implementation
答案 1 :(得分:0)
灰烬:
command=sh -c 'echo "READY"; while read -r line; do echo "$line"; supervisorctl shutdown; done'