I'm trying to configure logrotate with docker container. I'm running httpd as background process in docker container, and after logrotate I need to reload it to use new log files. I don't want to restart the container because of possible downtime. Sending SIGHUP with docker kill --signal=HUP <container>
is not working, as my entrypoint is bash script which does not handle signals. I tried to do it like this in logrotate config:
...
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
but I got
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
I'm quite new to docker and linux and I don't really understand why docker gets process ids that do not exist.
EDIT: I also would not like to change the bash script to trap SIGHUP if possible, but instead solve the problem in logrotate config.
I believe the
$(ps -e | awk '{print $1}')>>/tmp/exec-out.log 2>>/tmp/exec-out.log || true
is being run in the context of the host not the docker and so gets the wrong pid as you can see.If you ran the docker container with
pid=host
the pids will work.Alternatively you can get the pid like so:
docker inspect --format {{.State.Pid}} <container>
But you don't actually need the pid, you can send a signal yourself using
docker kill
like so:docker kill --signal=HUP some-container