我有一个 logrotate 服务配置如下,在用户 systemd 计时器上运行。
问题是允许旋转的目标增长超过 logrotate.conf 中指定的大小,并且不会被截断。
-rw-r--r-- 1 stephen stephen 14M 2023-06-04 08:15 monitor-iotop.log.1
-rw-r--r-- 1 stephen stephen 14M 2023-06-04 08:19 monitor-iotop.log
logrotate.conf
/mnt/ram/log/monitor-iotop.log {
size 500K
copytruncate
rotate 1
maxage 0
missingok
notifempty
su stephen stephen
}
计时器
[Unit]
Description=Logrotate Timer
[Timer]
OnCalendar=*:0/5
AccuracySec=1s
Unit=logrotate.service
[Install]
WantedBy=timers.target
服务:
[Unit]
Description=Logrotate Service
[Service]
ExecStart=/usr/sbin/logrotate -s /tmp/logrotate.state /hd2/projects/test/top/logrotate.conf
和journalctl -u logrotate.service
2023-05-22T00:00:00.443993-0700 meer systemd[1]: Starting Rotate log files...
2023-05-22T00:00:00.484405-0700 meer systemd[1]: logrotate.service: Deactivated successfully.
2023-05-22T00:00:00.513788-0700 meer systemd[1]: Finished Rotate log files.
2023-05-23T00:00:00.478533-0700 meer systemd[1]: Starting Rotate log files...
2023-05-23T00:00:00.506664-0700 meer systemd[1]: logrotate.service: Deactivated successfully.
2023-05-23T00:00:00.528445-0700 meer systemd[1]: Finished Rotate log files.
2023-05-24T00:00:00.433292-0700 meer systemd[1]: Starting Rotate log files...
2023-05-24T00:00:00.468817-0700 meer systemd[1]: logrotate.service: Deactivated successfully.
2023-05-24T00:00:00.496690-0700 meer systemd[1]: Finished Rotate log files.