我有一个linux应用程序,它不断地将日志信息写入日志文件,例如。/var/log/application.log。由于应用程序不能自动旋转文件,这个日志文件可以在几周内达到千兆字节的大小,所以我希望能够正确地旋转这个文件。
这里我主要关心的是,要旋转应用程序在任何时候打开的文件,我可能需要:
/var/log/application.log -> /var/log/application.log.2013-01-28/var/log/application.log。Obs:此时,应用程序仍在写入/var/log/application.log.2013-01-28/var/log/application.log所以,我说的对吗?如果是的话,我怎样才能做到呢?(主要是更改文件描述符部分)
如果我不是,什么是正确的方式和如何做呢?
发布于 2013-01-29 00:14:08
编写logrotate配置以使用copytruncate
copytruncate
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.发布于 2013-01-28 22:31:57
大多数这样的应用程序响应一个信号,如SIGHUP,并将关闭和重新打开他们的日志文件在收到信号。检查应用程序的文档,以获得要发送的正确信号。
https://serverfault.com/questions/473232
复制相似问题