2017-09-04 48 views
1

我想配置码头容器的logrotate。我在Docker容器中运行httpd作为后台进程,在logrotate之后,我需要重新加载它以使用新的日志文件。由于可能的停机时间,我不想重启容器。发送SIGHUP docker kill --signal=HUP <container>不起作用,因为我的入口点是不处理信号的bash脚本。我试图做这样的logrotate设置:Logrotate postrotate和码头执行器奇怪的行为

... 
sharedscripts 
postrotate 
    service httpd reload > /dev/null 2>/dev/null || true 
    docker exec some-container kill -HUP $(ps -e | awk '{print $1}')>>/tmp/exec-out.log 2>>/tmp/exec-out.log || true 
endscript 

,但我得到了

kill: sending signal to 30 failed: No such process 
kill: sending signal to 31 failed: No such process 
kill: sending signal to 32 failed: No such process 
kill: sending signal to 33 failed: No such process 
kill: sending signal to 34 failed: No such process 
kill: sending signal to 35 failed: No such process 
kill: sending signal to 36 failed: No such process 
kill: sending signal to 37 failed: No such process 
kill: sending signal to 38 failed: No such process 

我是很新的泊坞窗和Linux,我真的不明白,为什么泊坞窗获取进程ID是不存在。

编辑:我也不想改变bash脚本来捕捉SIGHUP,如果可能的话,而是在logrotate配置中解决问题。

回答

0

我相信$(ps -e | awk '{print $1}')>>/tmp/exec-out.log 2>>/tmp/exec-out.log || true正在主机的上下文中运行,而不是docker,因此您可以看到错误的pid。

如果您使用pid=host运行码头集装箱,则pid将起作用。

或者你可以得到PID像这样:

docker inspect --format {{.State.Pid}} <container>

但你实际上并不需要的PID,您可以发送自己使用docker kill的信号,像这样:

docker kill --signal=HUP some-container