我每个月都在尝试轮换 OpenVPN 日志文件。问题似乎是简单地重命名文件并不能解决问题。数据仍然被写入旧文件(这表明日志文件保持打开状态并且日志记录仍然写入旧文件对象)。
所以现在我编写了一个脚本,在它更新指向新日志文件位置的符号链接后,它会在每个月的月初重新启动 openvpn。
但是这个脚本似乎有问题,有时无法正确启动服务器(有时 tun0 关闭)。
所以我想问你们中是否有人知道在 OpenVPN 中实现日志轮换的更好方法?
编辑:我正在使用 Debian Squeeze 并且我的重启脚本在停止和启动ovpn
服务器之间已经休眠了 5 秒
jor*_*anm 10
有两种方法可以处理这种情况。让 logrotate 通过信号或通过postrotate
指令重新启动进程来通知进程的理想方法。另一种方法是使用copytruncate
. 该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 can not 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 log-
ging data might be lost. When this option is used, the create
option will have no effect, as the old log file stays in place.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7869 次 |
最近记录: |