I have the following cronjob which pipes docker (apache) logs into a file:

* * * * * flock -n /srv/www/htdocs/scripts/pipe.lock /srv/www/htdocs/scripts/pipe_docker_logs.sh

the pipe_docker_logs.sh simply does a:

tail -f `docker inspect --format='{{.LogPath}}' docker_apache` >& /var/log/apache2/docker_apache_access.log &

The file writen by this tail background process is rotated by logrotate.d

If the file is rotated, the tail process stops writing to the newly created file. Killing the tail process and waiting till cron restarts it, starts writing to the log file again.

Now I guess I would need some kill or restart command if the log is rotated. Maybe cron is the wrong place to do this and logrotate.d should do this? Any hints?
I know about ELK and fluent ... but this is just one container and would be overkill.

1 Answer 1


I am assuming that you have added custom instructions to logrotate to rotate this file. If so, then a workaround may be to use copytruncate. man page


Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

Here is an example.

rotate 14
create 640 root adm

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.