Как мне повернуть журнал моего приложения в Ubuntu?

Я использую Ubuntu Linux 14.04. У меня проблемы с ротацией журналов. У меня есть этот файл

rails@myapp:~$ ls -al myapp/log/production.log
-rw-r--r-- 1 rails rails 4522482443 Jun  5 12:11 myapp/log/production.log

, и он есть в моем файле /etc/logrotate.conf

/home/rails/myapp/log {
        daily
        rotate 4
        compress
        delaycompress
        missingok
        notifempty
        create 644 root root
}

, но мой журнал никогда не меняется. Я знаю это, потому что вижу записи в файле myapp / log / production.log, датированные 8 мая. С каждым днем ​​журнал становится все больше. Что еще мне нужно сделать для ротации журнала?

0
05.06.2017, 19:31
2 ответа

Во-первых, скорее всего, вы не запускаете logrotate автоматически (обычно через демон cron).

Во-вторых, вы указываете в своем файле конфигурации logrotate, что хотите повернуть файл /home/rails/myapp/log, но в выводе ls вы показываете нам файл /home/rails/myapp/log/production.log ( Я предполагаю ~rails -> /home/rails). И вы также просите, чтобы logrotate создал новый пустой файл журнала, чтобы иметь владельца root: root, но опять же в выводе ls исходный файл является собственностью rails: rails.

TL;DR; вместо этого используйте этот конфигурационный файл (и убедитесь, что logrotate время от времени запускается с помощью cron или аналогичной программы):

/home/rails/myapp/log/production.log {
        daily
        rotate 4
        compress
        delaycompress
        missingok
        notifempty
        create 644 rails rails
}

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

1
28.01.2020, 02:45

Попробуйте это.

/home/rails/myapp/log

{  
   su rails rails
   daily
   missingok
   compress
   notifempty
   rotate 12
   create
   delaycompress
   missingok
   }

Поместите его в /etc/logrotate.d/myapp

Очень небольшое пояснение. Logroatate должен быть записан в вашем $ HOME, поэтому поворот для вашего myapp.log должен выполняться как рельсы.

su rails rails   

извините больше из справочной страницы

su user group Rotate log files set under this user and group instead of using default user/group (usually root). user specifies the user name used for rotation and group specifies the group used for rotation. If the user/group you specify here does not have sufficient privilege to make files with the ownership you've specified in a create instruc‐ tion, it will cause an error.

create mode owner group, create owner group Immediately after rotation (before the postrotate script is run) the log file is created (with the same name as the log file just rotated). mode specifies the mode for the log file in octal (the same as chmod(2)), owner specifies the user name who will own the log file, and group specifies the group the log file will belong to. Any of the log file attributes may be omitted, in which case those attributes for the new file will use the same val‐ ues as the original log file for the omitted attributes. This option can be disabled using the nocreate option.

Извините, я не могу лучше объяснить по-английски.

0
28.01.2020, 02:45

Теги

Похожие вопросы