问题描述
我正在尝试为 supervisord 配置一个事件侦听器,但无法让它工作.我只想监听 PROCESS_STATE 更改并运行一些触发 urllib2request 的 python 代码.
I'm trying to configure an event listener for supervisord but can't get it to work.I just want to listen for PROCESS_STATE changes and run some python code triggering an urllib2request.
在我的 .conf 中,我有:
In my .conf I have:
[eventlistener:statechanges]
command=python listener.py
events=PROCESS_STATE
在 listener.py 中:
And in listener.py:
def run():
runFunc() # Function to trigger an urllib2request
if __name__ == '__main__':
run()
然后触发器不会启动,它只是在一些重试后进入 FATAL 状态.
Then the trigger won't start, it just enters the FATAL state after some retries.
statechanges entered FATAL state, too many start retries too quickly
任何想法或有人有如何为 supervisord 编写监听器的示例?
Any ideas or does someone have an example of how to write a listener for supervisord?
推荐答案
你不能只打印随机字符串,supervisord 会监听标准输出 :)
You can't just print random strings, supervisord listens at the stdout :)
文档中的这个例子怎么样:
How about this example from the docs:
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-监听器实现
这篇关于监督事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!