1

У меня есть конфиг logrotate, который работал нормально, пока вдруг он не перестал это делать. Я предполагаю, что он перестал вращать мой журнал после того, как я удалил и заново log папку журнала во время обновления моего приложения. Ниже приведены соответствующие части config и logrotate log.

/etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0660 root utmp
    rotate 1
}

# system-specific logs may be configured here
/var/lib/redmine/log/production.log{
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
}

После того, как я вручную запустил logrotate:

rotating pattern: /var/lib/redmine/log/production.log after 1 days (30 rotations)
empty log files are not rotated, old logs are removed
considering log /var/lib/redmine/log/production.log
  log needs rotating
rotating log /var/lib/redmine/log/production.log, log->rotateCount is 30
dateext suffix '-20151209'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/lib/redmine/log/production.log.30.gz to /var/lib/redmine/log/production.log.31.gz (rotatecount 30, logstart 1, i 30),
renaming /var/lib/redmine/log/production.log.29.gz to /var/lib/redmine/log/production.log.30.gz (rotatecount 30, logstart 1, i 29),
renaming /var/lib/redmine/log/production.log.28.gz to /var/lib/redmine/log/production.log.29.gz (rotatecount 30, logstart 1, i 28),
renaming /var/lib/redmine/log/production.log.27.gz to /var/lib/redmine/log/production.log.28.gz (rotatecount 30, logstart 1, i 27),
renaming /var/lib/redmine/log/production.log.26.gz to /var/lib/redmine/log/production.log.27.gz (rotatecount 30, logstart 1, i 26),
renaming /var/lib/redmine/log/production.log.25.gz to /var/lib/redmine/log/production.log.26.gz (rotatecount 30, logstart 1, i 25),
renaming /var/lib/redmine/log/production.log.24.gz to /var/lib/redmine/log/production.log.25.gz (rotatecount 30, logstart 1, i 24),
renaming /var/lib/redmine/log/production.log.23.gz to /var/lib/redmine/log/production.log.24.gz (rotatecount 30, logstart 1, i 23),
renaming /var/lib/redmine/log/production.log.22.gz to /var/lib/redmine/log/production.log.23.gz (rotatecount 30, logstart 1, i 22),
renaming /var/lib/redmine/log/production.log.21.gz to /var/lib/redmine/log/production.log.22.gz (rotatecount 30, logstart 1, i 21),
renaming /var/lib/redmine/log/production.log.20.gz to /var/lib/redmine/log/production.log.21.gz (rotatecount 30, logstart 1, i 20),
renaming /var/lib/redmine/log/production.log.19.gz to /var/lib/redmine/log/production.log.20.gz (rotatecount 30, logstart 1, i 19),
renaming /var/lib/redmine/log/production.log.18.gz to /var/lib/redmine/log/production.log.19.gz (rotatecount 30, logstart 1, i 18),
renaming /var/lib/redmine/log/production.log.17.gz to /var/lib/redmine/log/production.log.18.gz (rotatecount 30, logstart 1, i 17),
renaming /var/lib/redmine/log/production.log.16.gz to /var/lib/redmine/log/production.log.17.gz (rotatecount 30, logstart 1, i 16),
renaming /var/lib/redmine/log/production.log.15.gz to /var/lib/redmine/log/production.log.16.gz (rotatecount 30, logstart 1, i 15),
renaming /var/lib/redmine/log/production.log.14.gz to /var/lib/redmine/log/production.log.15.gz (rotatecount 30, logstart 1, i 14),
renaming /var/lib/redmine/log/production.log.13.gz to /var/lib/redmine/log/production.log.14.gz (rotatecount 30, logstart 1, i 13),
renaming /var/lib/redmine/log/production.log.12.gz to /var/lib/redmine/log/production.log.13.gz (rotatecount 30, logstart 1, i 12),
renaming /var/lib/redmine/log/production.log.11.gz to /var/lib/redmine/log/production.log.12.gz (rotatecount 30, logstart 1, i 11),
renaming /var/lib/redmine/log/production.log.10.gz to /var/lib/redmine/log/production.log.11.gz (rotatecount 30, logstart 1, i 10),
renaming /var/lib/redmine/log/production.log.9.gz to /var/lib/redmine/log/production.log.10.gz (rotatecount 30, logstart 1, i 9),
renaming /var/lib/redmine/log/production.log.8.gz to /var/lib/redmine/log/production.log.9.gz (rotatecount 30, logstart 1, i 8),
renaming /var/lib/redmine/log/production.log.7.gz to /var/lib/redmine/log/production.log.8.gz (rotatecount 30, logstart 1, i 7),
renaming /var/lib/redmine/log/production.log.6.gz to /var/lib/redmine/log/production.log.7.gz (rotatecount 30, logstart 1, i 6),
renaming /var/lib/redmine/log/production.log.5.gz to /var/lib/redmine/log/production.log.6.gz (rotatecount 30, logstart 1, i 5),
renaming /var/lib/redmine/log/production.log.4.gz to /var/lib/redmine/log/production.log.5.gz (rotatecount 30, logstart 1, i 4),
renaming /var/lib/redmine/log/production.log.3.gz to /var/lib/redmine/log/production.log.4.gz (rotatecount 30, logstart 1, i 3),
renaming /var/lib/redmine/log/production.log.2.gz to /var/lib/redmine/log/production.log.3.gz (rotatecount 30, logstart 1, i 2),
renaming /var/lib/redmine/log/production.log.1.gz to /var/lib/redmine/log/production.log.2.gz (rotatecount 30, logstart 1, i 1),
renaming /var/lib/redmine/log/production.log.0.gz to /var/lib/redmine/log/production.log.1.gz (rotatecount 30, logstart 1, i 0),
renaming /var/lib/redmine/log/production.log to /var/lib/redmine/log/production.log.1
creating new /var/lib/redmine/log/production.log mode = 0644 uid = 1000 gid = 1000
removing old log /var/lib/redmine/log/production.log.31.gz
error: error opening /var/lib/redmine/log/production.log.31.gz: No such file or directory

После того, как я перечислю каталог журнала:

ll /var/lib/redmine/log/
total 178484
drwxrwxr-x  2 redmine redmine      4096 Dec  9 12:05 ./
drwxr-xr-x 20 redmine redmine      4096 Dec  6 23:56 ../
-rw-rw-r--  1 redmine redmine     49581 Dec  8 14:47 development.log
-rw-r--r--  1 redmine redmine 182700709 Dec  9 12:05 production.log

Так что он говорит, что он вращал файл журнала, но на самом деле ничего не произошло. Что может быть причиной этого?

2 ответа2

1

Одной из причин может быть то, что вы перечисляете свои журналы как пользователь redmine, в то время как logrotate работает как root, поэтому в списке каталогов они не отображаются.

Я бы лучше создал файл /etc/logrotate.d/redmine со следующим содержимым:

/path/to/your/redmine/log/production.log {
daily
missingok
rotate 31
compress
delaycompress
notifempty
copytruncate
} 

Затем проверьте:

sudo /usr/sbin/logrotate -f /etc/logrotate.d/redmine
0

Проблема оказалась неверной прав доступа к папке log . Logrotate не будет обрабатывать его, потому что у него был доступ на запись группы. После запуска chmod 755 в папке журнала все стало работать.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .