Supervisord - 将进程stdout重定向到控制台

时间:2014-08-08 04:04:49

标签: linux supervisord child-process

我打算使用supervisor运行多个进程,请在下面找到我的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的进程的stdout重定向到超级用户控制台,这样当我使用

启动主管时
/usr/bin/supervisord

命令,我可以看到子进程日志。我怎样才能做到这一点 ?我尝试将stlog用于stdout_logfile属性,但它没有用。

2 个答案:

答案 0 :(得分:71)

您可以使用以下配置选项将程序的标准输出重定向到主管的标准输出:

stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

说明:

  • 当进程打开/dev/fd/1(与/proc/self/fd/1相同)时,系统实际克隆该进程的文件描述符#1(stdout)。因此将stdout_logfile用作supervisord会导致stdout_logfile_maxbytes=0将程序的标准输出重定向到自己的标准输出。
  • {{1}}禁用日志文件轮换,这显然对stdout没有意义。不指定此选项将导致错误,因为默认值为50MB且supervisor不够智能,无法检测到指定的日志文件不是常规文件。

了解更多信息:

http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html

答案 1 :(得分:0)

更新

请参阅示例会话中的以下脚本。 Supervisord肯定会抓住ping的标准。你还需要什么?

(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守护程序的bash控制台不会打印任何内容。您需要通过supervisorctl命令通过Unix域套接字连接到守护程序,该套接字的路径是您使用serverurl = unix:///tmp/supervisor.sockfile = /tmp/supervisor.sock行指定的。

(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$

此外,Web GUI非常方便。将这些行添加到配置文件中:

[inet_http_server]
port = 127.0.0.1:9001

有关详细信息,请参阅the official document

相关问题