使用supervisord,是否可以运行一个进程而不拦截stdout?

使用supervisord,是否可以运行一个进程而不拦截stdout?

我有一个在 kubernetes pod 中运行 Supervisord 的 docker 镜像。我希望通过 Supervisord 运行的进程的输出出现在 k8s 日志中。似乎最简单的方法是让子进程直接写入 Supervisord 的标准输出。为此,我可以执行以下可怕的黑客攻击:

root@714811eb811b:/tmp# cat a.sh
#!/bin/sh

exec > /proc/$(cat /tmp/supervisord.pid)/fd/1
echo This text goes to the k8s log
root@714811eb811b:/tmp# cat config
[supervisord]
nodaemon=true
pidfile=/tmp/supervisord.pid

[program:write]
command=/tmp/a.sh
exitcodes=0
root@714811eb811b:/tmp# supervisord -c config
2017-12-02 00:34:14,245 CRIT Supervisor running as root (no user in config file)
2017-12-02 00:34:14,248 INFO supervisord started with pid 451
2017-12-02 00:34:15,256 INFO spawned: 'write' with pid 454
This text goes to the k8s log
2017-12-02 00:34:15,262 INFO exited: write (exit status 0; not expected)
2017-12-02 00:34:16,270 INFO spawned: 'write' with pid 456
This text goes to the k8s log
2017-12-02 00:34:16,276 INFO exited: write (exit status 0; not expected)
^C2017-12-02 00:34:17,027 WARN received SIGINT indicating exit request

如上所述,这是一个糟糕的黑客行为。有没有合适的方法告诉 Supervisord 将子进程的标准输出绑定到自己的标准输出?(即告诉 Supervisord 什么都不做,只让子进程继承正常的文件描述符)

顺便提一下,为什么脚本要重新启动?即使没有明确指定退出代码,supervisord 也应该期望退出代码为 0。

相关内容