我打算使用supervisor运行多个进程,请在下面find我的supervisord.conf文件:
[supervisord] [program:bash] command=xyz stdout_logfile =/tmp/bash.log redirect_stderr=true [supervisorctl] serverurl=unix:///tmp/supervisor.sock [unix_http_server] file=/tmp/supervisor.sock ; path to your socket file [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
我希望将名为bash的进程的stdoutredirect到supervisor控制台,以便在启动supervisor时使用
/usr/bin/supervisord
命令,我可以看到subprocess日志。 我怎样才能做到这一点 ? 我试图把系统日志stdout_logfile属性,但它没有工作。
您可以使用以下配置选项将程序的stdout重定向到supervisor的stdout:
stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0
说明:
/dev/fd/1
(与/proc/self/fd/1
)时,系统实际上会克隆该进程的文件描述符#1(stdout)。 因此,使用这个stdout_logfile
会导致supervisord
将程序的stdout重定向到它自己的stdout。 stdout_logfile_maxbytes=0
禁用日志文件的旋转,这显然对stdout没有意义。 不指定此选项会导致错误,因为默认值是50MB,而且管理程序不够智能,无法检测到指定的日志文件不是常规文件。 了解更多信息:
http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html
从示例会话中查看下面的记录。 Supervisord肯定会捕获ping的stdout。 你还需要什么?
(svd)08/09 16:26 [nodakai@kaidev01] ~/prog/svd$ cat supervisord.conf [supervisord] [program:ping] command=ping 8.8.8.8 stdout_logfile =/tmp/ping.log redirect_stderr=true [supervisorctl] serverurl=unix:///tmp/supervisor.sock [unix_http_server] file = /tmp/supervisor.sock [inet_http_server] port = 127.0.0.1:9001 [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface (svd)08/09 16:26 [nodakai@kaidev01] ~/prog/svd$ supervisorctl -c supervisord.conf ping RUNNING pid 27365, uptime 0:02:02 supervisor> tail ping : icmp_req=97 ttl=48 time=59.1 ms 64 bytes from 8.8.8.8: icmp_req=98 ttl=48 time=59.2 ms 64 bytes from 8.8.8.8: icmp_req=99 ttl=48 time=59.1 ms 64 bytes from 8.8.8.8: icmp_req=100 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=101 ttl=48 time=59.8 ms 64 bytes from 8.8.8.8: icmp_req=102 ttl=48 time=59.2 ms 64 bytes from 8.8.8.8: icmp_req=103 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=104 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=105 ttl=48 time=59.6 ms 64 bytes from 8.8.8.8: icmp_req=106 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=107 ttl=48 time=60.1 ms 64 bytes from 8.8.8.8: icmp_req=108 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=109 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=110 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=111 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=112 ttl=48 time=59.1 ms 64 bytes from 8.8.8.8: icmp_req=113 ttl=48 time=59.3 ms 64 bytes from 8.8.8.8: icmp_req=114 ttl=48 time=59.2 ms 64 bytes from 8.8.8.8: icmp_req=115 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=116 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=117 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=118 ttl=48 time=59.6 ms 64 bytes from 8.8.8.8: icmp_req=119 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=120 ttl=48 time=59.4 ms 64 bytes from 8.8.8.8: icmp_req=121 ttl=48 time=59.2 ms 64 bytes from 8.8.8.8: icmp_req=122 ttl=48 time=59.3 ms 64 bytes from 8.8.8.8: icmp_req=123 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=124 ttl=48 time=59.5 ms 64 bytes from 8.8.8.8: icmp_req=125 ttl=48 time=59.3 ms supervisor>
实际上我读了你的回复是有些困惑,因为这是supervisord
守护进程的基本功能。 也许对你所谓的“supervisord主机”有一些误解? 用来启动supervisord
守护进程的bash控制台不会打印任何东西。 您需要通过supervisorctl
命令通过您使用serverurl = unix:///tmp/supervisor.sock
和file = /tmp/supervisor.sock
行指定路径的Unix域套接字连接到守护进程。
(svd)08/09 3:51 [nodakai@kaidev01] ~/prog/svd$ supervisorctl -c supervisord.conf foo FATAL Exited too quickly (process log may have details) supervisor> help default commands (type help <topic>): ===================================== add clear fg open quit remove restart start stop update avail exit maintail pid reload reread shutdown status tail version supervisor> tail foo -rw-r-- 1 nodakai nodakai 1521 8月 9 03:43 supervisord.log -rw-r--r-- 1 nodakai nodakai 6 8月 9 03:43 supervisord.pid合計 32 drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:10 bin drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 include drwxrwxr-x 3 nodakai nodakai 4096 8月 9 03:07 lib drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 local -rw-rw-r-- 1 nodakai nodakai 346 8月 9 03:43 supervisord.conf -rw-rw-r-- 1 nodakai nodakai 340 8月 9 03:42 supervisord.conf~ -rw-rw-r-- 1 nodakai nodakai 1651 8月 9 03:43 supervisord.log -rw-r--r-- 1 nodakai nodakai 6 8月 9 03:43 supervisord.pid合計 32 drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:10 bin drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 include drwxrwxr-x 3 nodakai nodakai 4096 8月 9 03:07 lib drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 local -rw-rw-r-- 1 nodakai nodakai 346 8月 9 03:43 supervisord.conf -rw-rw-r-- 1 nodakai nodakai 340 8月 9 03:42 supervisord.conf~ -rw-rw-r-- 1 nodakai nodakai 1781 8月 9 03:43 supervisord.log -rw-r--r-- 1 nodakai nodakai 6 8月 9 03:43 supervisord.pid合計 32 drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:10 bin drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 include drwxrwxr-x 3 nodakai nodakai 4096 8月 9 03:07 lib drwxrwxr-x 2 nodakai nodakai 4096 8月 9 03:07 local -rw-rw-r-- 1 nodakai nodakai 346 8月 9 03:43 supervisord.conf -rw-rw-r-- 1 nodakai nodakai 340 8月 9 03:42 supervisord.conf~ -rw-rw-r-- 1 nodakai nodakai 1911 8月 9 03:43 supervisord.log -rw-r--r-- 1 nodakai nodakai 6 8月 9 03:43 supervisord.pid supervisor> status foo FATAL Exited too quickly (process log may have details) supervisor> quit (svd)08/09 3:51 [nodakai@kaidev01] ~/prog/svd$
而且,网页界面非常方便。 将这些行添加到您的配置文件中:
[inet_http_server] port = 127.0.0.1:9001
有关详细信息,请参阅官方文档 。