关于Supervisor和Apache的error.log尾部的说明
在创build一个Docker容器的时候,为了同时拥有apache2的 error.log
和通过docker logs -f <my_container>
它,我使用一个运行supervisor的容器作为这个configuration的入口点 :
[supervisord] nodaemon = true environment = PLACEHOLDER=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:apache] command=apache2ctl -DFOREGROUND autostart=true autorestart=true startretries=1 startsecs=1 stderr_logfile=/var/log/apache2/error.log stdout_logfile=/var/log/apache2/access.log user=root killasgroup=true stopasgroup=true [program:apache2-error] command= tail -f /var/log/apache2/error.log autostart = true autorestart = true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:apache2-access] command= tail -f /var/log/apache2/access.log autostart = true autorestart = true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0
这工作正常,但我不明白为什么这不工作,如果我用这个replace[program:apache]
会话:
[program:apache] command=apache2ctl -DFOREGROUND autostart=true autorestart=true startretries=1 startsecs=1 user=root killasgroup=true stopasgroup=true
也就是说:如果没有明确设置stderr
和stdout
日志文件, docker logs -f <my_container>
命令不起作用,但是在container tail -f /var/logs/apache2/access.log
和tail -f /var/logs/apache2/error.log
工作正常。
有人可以解释为什么supervisor
和docker logs -f <my_container>
有两个不同的作品,由于这种configuration的变化?
谢谢
主pipe可以“看”apache2的标准输出,并将其写入到您使用stdout_file指定的文件中。 问题是apache2不会将它写入stdout的访问日志,而是将它写入/ var / log / apache2中的文件。
所以,你在docker logs -f
中看到的是docker logs -f
是pipe理员正在对你在stdout_file
提供的文件进行的stdout_file
并且pipe理程序正如你在[supervosord]
configuration的那样将它转发到它自己的stdout
。
因此,当您从主pipe中删除apache2日志文件configuration时,没有这样的转发; 和apache2继续写入与以前相同的文件。
所以,你需要做的是告诉Apache把它的访问日志写到/ dev / stdout而不是磁盘上的文件。 您可以在Apache虚拟主机configuration中执行此操作。
stderr
。