我試圖使用supervisord事件來監聽Supervisor管理的進程中的PROCESS_STATE_STOPPED
事件。主管活動:如何監聽所有或指定進程的PROCESS_STATE_STOPPED事件
我的事件監聽器(listener.py
),看起來是這樣的:
import sys
from supervisor.childutils import listener
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 True:
headers, body = listener.wait(sys.stdin, sys.stdout)
body = dict([pair.split(":") for pair in body.split(" ")])
write_stderr("Headers: %r\n" % repr(headers))
write_stderr("Body: %r\n" % repr(body))
listener.ok(sys.stdout)
if headers["eventname"] == "PROCESS_STATE_STOPPED":
write_stderr("Process state stopped...\n")
if __name__ == '__main__':
main()
在supervisord.conf
我相應的條目如下:
[program:theprogramname]
command=/bin/cat ; the program (relative uses PATH, can take args)
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
...
[eventlistener:theeventlistenername]
command=python /home/mickm/listener.py ; the program (relative uses PATH, can take args)
process_name=%(program_name)s_%(process_num)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
events=PROCESS_STATE ; event notif. types to subscribe to (req'd)
autorestart=true
redirect_stderr=true
我已經研究了這個區域&其他StackOverflow的問題我試圖實施公認的解決方案:
- How to subscribe to PROCESS_STATE_RUNNING events for all processes
- Supervisor event subscription is hanging on READY state
然而,當我運行listener.py
,輸出READY
到SDOUT &去沒有進一步。我試過停止/啓動&重新啓動監督進程,但我的腳本確實收拾任何東西。
爲了測試這一點,我:
- 運行在終端我的事件偵聽器的腳本;
- 在終端B.在
/bin/cat
過程進行kill -9 <pid>
我的上司日誌如下:
2017-01-13 14:56:36,168 INFO success: theeventlistenername_0 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2017-01-13 14:56:36,168 INFO success: theprogramname entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2017-01-13 14:57:29,457 INFO exited: theprogramname (terminated by SIGKILL; not expected)
2017-01-13 14:57:30,460 INFO spawned: 'theprogramname' with pid 25788
2017-01-13 14:57:31,462 INFO success: theprogramname entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
雖然主管日誌知道我的進程已被終止:
i)listener.py
沒有檢測到任何東西,它保持'READY'提示。
ii)監督員重新啓動以處理(如預期的)。
我想知道爲什麼聽衆沒有收到配置文件中定義的程序的PROCESS_STATE_STOPPED
事件(按照Supervisor事件docs)。另外 - 這是否可以普遍適用於所有主管管理的流程。
謝謝。
您是否嘗試過重新啓動supervisord服務? – lapinkoira
你能重新啓動任何supervisorctl過程嗎?或者殺了它?並檢查是否正在生成error.log – lapinkoira
啊我看到了,在使用eventlistener時也沒有使用redirect_stderr,請檢查我的編輯 – lapinkoira