logrotate escrevendo para o antigo app.log.1 em vez de app.log

1

Nós temos uma aplicação customizada que está usando syslog para logging. Agora estamos enfrentando um problema com logrotate que logs estão sendo gravados em urls.log.1 ao invés de urls.log, logrotate não criando url.log após a rotação. estamos usando o servidor Ubuntu 14.04 LTS. Como podemos forçar o logrotate a criar o urls.log após a rotação?

logrotate config (/etc/logrotate.d/rsyslog)

/usr/local/app/log/urls.log
{
        rotate 10
        daily
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        su app app
        postrotate
                reload rsyslog >/dev/null 2>&1 || true
        endscript
}

Se eu manualmente mv urls.log.1 para urls.log e executo forçar logrotate, esta será a saída

considering log /usr/local/app/log/urls.log
  log needs rotating
rotating log /usr/local/app/log/urls.log, log->rotateCount is 10
dateext suffix '-20170228'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
switching uid to 1000 and gid to 1000
renaming /usr/local/app/log/urls.log.10.gz to /usr/local/app/log/urls.log.11.gz (rotatecount 10, logstart 1, i 10), 
renaming /usr/local/app/log/urls.log.9.gz to /usr/local/app/log/urls.log.10.gz (rotatecount 10, logstart 1, i 9), 
renaming /usr/local/app/log/urls.log.8.gz to /usr/local/app/log/urls.log.9.gz (rotatecount 10, logstart 1, i 8), 
renaming /usr/local/app/log/urls.log.7.gz to /usr/local/app/log/urls.log.8.gz (rotatecount 10, logstart 1, i 7), 
renaming /usr/local/app/log/urls.log.6.gz to /usr/local/app/log/urls.log.7.gz (rotatecount 10, logstart 1, i 6), 
renaming /usr/local/app/log/urls.log.5.gz to /usr/local/app/log/urls.log.6.gz (rotatecount 10, logstart 1, i 5), 
renaming /usr/local/app/log/urls.log.4.gz to /usr/local/app/log/urls.log.5.gz (rotatecount 10, logstart 1, i 4), 
renaming /usr/local/app/log/urls.log.3.gz to /usr/local/app/log/urls.log.4.gz (rotatecount 10, logstart 1, i 3), 
renaming /usr/local/app/log/urls.log.2.gz to /usr/local/app/log/urls.log.3.gz (rotatecount 10, logstart 1, i 2), 
renaming /usr/local/app/log/urls.log.1.gz to /usr/local/app/log/urls.log.2.gz (rotatecount 10, logstart 1, i 1), 
renaming /usr/local/app/log/urls.log.0.gz to /usr/local/app/log/urls.log.1.gz (rotatecount 10, logstart 1, i 0), 
old log /usr/local/app/log/urls.log.0.gz does not exist
renaming /usr/local/app/log/urls.log to /usr/local/app/log/urls.log.1
running postrotate script
switching euid to 0 and egid to 0
removing old log /usr/local/app/log/urls.log.11.gz
switching euid to 0 and egid to 0

Se eu forçar a execução do logrotate novamente, esta será a saída

    rotating pattern: /usr/local/app/log/urls.log 
 forced from command line (100 rotations)
empty log files are not rotated, old logs are removed
switching euid to 1000 and egid to 1000
considering log /usr/local/app/log/urls.log  
  log /usr/local/app/log/urls.log does not exist -- skipping  ## urls.log is not creating
not running postrotate script, since no logs were rotated
switching euid to 0 and egid to 0
    
por Shyam Jos 28.02.2017 / 18:33

1 resposta

1

Você pode usar a opção 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 logging data might be lost. [...]

Com esta opção, você pode não ter que usar o postrotate bit.

    
por 28.02.2017 / 20:13