我正在使用superervisord中的Event协议发送“TICK'每X秒钟对我的每个进程发生一次事件。问题是我想要运行这些进程的池(numprocs
= 4),并且每个进程都要接收信号。我所看到的是,只有一个进程实际接收到TICK信号,其他进程没有收到任何信号。
我已将问题解决为简单的python脚本。此脚本采用单个参数,用于生成日志文件的文件名。在日志文件中,记录信号。我希望如果我使用supervisord启动其中4个脚本,那么我会得到4个随时间增长的日志文件。相反,我得到一个增长的文件。这是python脚本event.py
:
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 write(name):
with open(name, 'a') as f:
f.write("signal\n")
def main():
if len(sys.argv) > 1:
name = "%s.txt" % sys.argv[1]
else:
name ="0.txt"
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
write(name)
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
以下是我配置supervisord eventlistener的方法:
[eventlistener:test]
numprocs=4
process_name=test-300%(process_num)02d
command=python /home/blah/event.py 300%(process_num)02d
directory=/home/blah
events=TICK_5
stopsignal=INT
stopwaitsecs=15
autostart=true
autorestart=true
以下是来自supervisord的日志:
$:) sudo tail -n500 /var/log/supervisor/*
==> /var/log/supervisor/supervisord.log <==
2014-12-29 16:45:12,752 CRIT Supervisor running as root (no user in config file)
2014-12-29 16:45:12,752 WARN Included extra file "/etc/supervisor/conf.d/supervisor-vpserver.conf" during parsing
2014-12-29 16:45:12,755 TRAC 127.0.0.1:Medusa (V1.12) started at Mon Dec 29 16:45:12 2014
Hostname: localhost
Port:9001
2014-12-29 16:45:12,785 INFO RPC interface 'supervisor' initialized
2014-12-29 16:45:12,786 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2014-12-29 16:45:12,786 TRAC /var/run/supervisor.sock:Medusa (V1.12) started at Mon Dec 29 16:45:12 2014
Hostname: <unix domain socket>
Port:/var/run/supervisor.sock
2014-12-29 16:45:12,786 INFO RPC interface 'supervisor' initialized
2014-12-29 16:45:12,786 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-12-29 16:45:12,787 BLAT supervisord forked; parent exiting
2014-12-29 16:45:12,787 INFO daemonizing the supervisord process
2014-12-29 16:45:12,788 INFO supervisord started with pid 15766
2014-12-29 16:45:13,791 INFO spawned: 'test-30002' with pid 15775
2014-12-29 16:45:13,793 INFO spawned: 'test-30003' with pid 15776
2014-12-29 16:45:13,795 INFO spawned: 'test-30000' with pid 15777
2014-12-29 16:45:13,798 INFO spawned: 'test-30001' with pid 15778
2014-12-29 16:45:13,817 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state STARTING> (stdout)>
2014-12-29 16:45:13,818 DEBG 'test-30002' stdout output:
READY
2014-12-29 16:45:13,818 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,819 BLAT read event caused by <PEventListenerDispatcher at 140274918531512 for <Subprocess at 140274918760528 with name test-30003 in state STARTING> (stdout)>
2014-12-29 16:45:13,819 DEBG 'test-30003' stdout output:
READY
2014-12-29 16:45:13,819 DEBG test-30003: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,829 BLAT read event caused by <PEventListenerDispatcher at 140274918532088 for <Subprocess at 140274918706928 with name test-30000 in state STARTING> (stdout)>
2014-12-29 16:45:13,829 DEBG 'test-30000' stdout output:
READY
2014-12-29 16:45:13,829 DEBG test-30000: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,829 BLAT read event caused by <PEventListenerDispatcher at 140274918532664 for <Subprocess at 140274918707072 with name test-30001 in state STARTING> (stdout)>
2014-12-29 16:45:13,829 DEBG 'test-30001' stdout output:
READY
2014-12-29 16:45:13,829 DEBG test-30001: ACKNOWLEDGED -> READY
2014-12-29 16:45:14,830 INFO success: test-30002 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,830 INFO success: test-30003 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,831 INFO success: test-30000 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,831 INFO success: test-30001 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:16,833 DEBG event 0 sent to listener test-30002
2014-12-29 16:45:16,833 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:16,833 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY
2014-12-29 16:45:16,833 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:16,833 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:16,834 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:16,834 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:0 pool:test poolserial:0 eventname:TICK_5 len:15
when:1419871515
2014-12-29 16:45:21,839 DEBG event 1 sent to listener test-30002
2014-12-29 16:45:21,839 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:21,840 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY
2014-12-29 16:45:21,840 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:21,840 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:21,840 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:21,840 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:1 pool:test poolserial:1 eventname:TICK_5 len:15
when:1419871520
2014-12-29 16:45:26,846 DEBG event 2 sent to listener test-30002
2014-12-29 16:45:26,846 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:26,846 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY
2014-12-29 16:45:26,846 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:26,846 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:26,846 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:26,846 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:2 pool:test poolserial:2 eventname:TICK_5 len:15
when:1419871525
2014-12-29 16:45:31,852 DEBG event 3 sent to listener test-30002
2014-12-29 16:45:31,852 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:31,853 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY
2014-12-29 16:45:31,853 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:31,853 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:31,853 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:31,853 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:3 pool:test poolserial:3 eventname:TICK_5 len:15
when:1419871530
==> /var/log/supervisor/test-30000-stderr---supervisor-NystkJ.log <==
==> /var/log/supervisor/test-30000-stdout---supervisor-h4mTFE.log <==
READY
==> /var/log/supervisor/test-30001-stderr---supervisor-zJJKe7.log <==
==> /var/log/supervisor/test-30001-stdout---supervisor-936BaW.log <==
READY
==> /var/log/supervisor/test-30002-stderr---supervisor-NXzezy.log <==
ver:3.0 server:supervisor serial:0 pool:test poolserial:0 eventname:TICK_5 len:15
when:1419871515ver:3.0 server:supervisor serial:1 pool:test poolserial:1 eventname:TICK_5 len:15
when:1419871520ver:3.0 server:supervisor serial:2 pool:test poolserial:2 eventname:TICK_5 len:15
when:1419871525ver:3.0 server:supervisor serial:3 pool:test poolserial:3 eventname:TICK_5 len:15
when:1419871530
==> /var/log/supervisor/test-30002-stdout---supervisor-K_tGpa.log <==
READY
RESULT 2
OKREADY
RESULT 2
OKREADY
RESULT 2
OKREADY
RESULT 2
OKREADY
==> /var/log/supervisor/test-30003-stderr---supervisor-mOXclj.log <==
==> /var/log/supervisor/test-30003-stdout---supervisor-6Q521a.log <==
READY
在我看来,test-30002
是产生4个进程中的第一个(最低PID),因此它是接收事件的进程。所有其他人都被排除在外。使用eventlistener
组和numprocs
&gt;时是否存在此已知行为? 1?
更新:
我可能还应该补充一点:
$:) supervisord --version
3.0b2