Logrotate no funciona en /tmp

Logrotate no funciona en /tmp

Me enfrento a un problema extraño con logrotate en mi servidor Debian 10.

Todo en uno, logrotate (v3.20.1) funciona y rota bien... excepto por algunos archivos en /tmp que quiero "skrink" todos los días. Esos registros son archivos CVS de Collectd que no necesito conservar más de 24 horas.

Mi archivo de configuración recopilado es:

/var/log/collectd/collectd.log {
        weekly
        rotate 4
        create
        compress
        missingok
}

/tmp/collectd/csv/localhost/*/* {
        daily
        rotate 0
        copytruncate
        missingok
}

Aquí hay una parte del archivo de registro de logrotate:

rotating pattern: /var/log/collectd/collectd.log  weekly (4 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/collectd/collectd.log
  Now: 2022-12-09 00:00
  Last rotated at 2022-12-04 15:15
  log does not need rotating (log has been rotated at 2022-12-04 15:15, which is less than a week ago)

rotating pattern: /tmp/collectd/csv/localhost/*/*  after 1 days (no old logs will be kept)
empty log files are rotated
considering log /tmp/collectd/csv/localhost/*/*

Lo extraño que puedo notar es en el archivo de estado de logrotate /var/lib/logrotate/status donde la fecha de estado está bloqueada en 2022-12-1-0:0:0 para esos archivos a diferencia de las otras entradas.

# cat /var/lib/logrotate/status | sort
logrotate state -- version 2
"/tmp/collectd/csv/localhost/*/*" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/cpu-0/cpu-idle" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/cpu-0/cpu-interrupt" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/cpu-0/cpu-nice" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/cpu-0/cpu-softirq" 2022-12-1-0:0:0
...
"/tmp/collectd/csv/localhost/tcpconns-4772-remote/tcp_connections-SYN_SENT" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/tcpconns-4772-remote/tcp_connections-TIME_WAIT" 2022-12-1-0:0:0
"/tmp/collectd/csv/localhost/uptime/uptime" 2022-12-1-0:0:0
...
"/var/log/borgbackup.log" 2022-12-4-15:15:18
"/var/log/btmp" 2022-12-1-0:0:1
"/var/log/chrony/*.log" 2022-1-13-18:0:0
"/var/log/clamav/clamav.log" 2022-12-4-15:15:18
"/var/log/clamav/freshclam.log" 2022-12-4-15:15:18
"/var/log/collectd/collectd.log" 2022-12-4-15:15:18

Intenté ejecutar logrotate en modo de depuración y aquí está el resultado:

...
rotating pattern: /tmp/collectd/csv/localhost/*/*  after 1 days (no old logs will be kept)
empty log files are rotated
considering log /tmp/collectd/csv/localhost/cpu-0/cpu-idle
  Now: 2022-12-09 17:32
  Last rotated at 2022-12-01 00:00
  log needs rotating
...
rotating log /tmp/collectd/csv/localhost/cpu-0/cpu-idle, log->rotateCount is 0
dateext suffix '-20221209'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /tmp/collectd/csv/localhost/cpu-0/cpu-idle.1.bz2 to /tmp/collectd/csv/localhost/cpu-0/cpu-idle.2.bz2 (rotatecount 1, logstart 1, i 1),
renaming /tmp/collectd/csv/localhost/cpu-0/cpu-idle.0.bz2 to /tmp/collectd/csv/localhost/cpu-0/cpu-idle.1.bz2 (rotatecount 1, logstart 1, i 0),
log /tmp/collectd/csv/localhost/cpu-0/cpu-idle.2.bz2 doesn't exist -- won't try to dispose of it
skip copying /tmp/collectd/csv/localhost/cpu-0/cpu-idle to /tmp/collectd/csv/localhost/cpu-0/cpu-idle.1
truncating /tmp/collectd/csv/localhost/cpu-0/cpu-idle
compressing log with: /bin/lbzip2
...

Pero el archivo no se rota a medianoche todos los días y sigue creciendo :(

¿Es posible rotar un archivo en /tmp? Parece que es posible pero ¿cuál podría ser el problema?

Gracias por tu ayuda.

Respuesta1

Debe verificar /lib/systemd/system/logrotate.servicela configuración y asegurarse de que PrivateTmpla opción esté configurada en false.

No lo olvidesystemctl daemon-reload

Acabo de descubrir por mí mismo que Logrotate no lo maneja Cron sino el temporizador Systemd. ¡Descubrimiento del año!

Respuesta2

Aquí está mi archivo de configuración systemd para el servicio logrotate.

# cat logrotate.service
[Unit]
Description=Rotate log files
Documentation=man:logrotate(8) man:logrotate.conf(5)
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/sbin/logrotate -v --log=/var/log/logrotate/logrotate.log /etc/logrotate.conf

# performance options
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

# hardening options
#  details: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
#  no ProtectHome for userdir logs
#  no PrivateNetwork for mail deliviery
#  no ProtectKernelTunables for working SELinux with systemd older than 235
#  no MemoryDenyWriteExecute for gzip on i686
PrivateDevices=true
PrivateTmp=false
ProtectControlGroups=true
ProtectKernelModules=true
ProtectSystem=full
RestrictRealtime=true

información relacionada