I'm using Ubuntu 14.04. I have the following in my /etc/logrotate.conf file ...
/home/rails/myproject/log {
daily
rotate 3
compress
delaycompress
missingok
notifempty
create 644 rails rails
}
/var/log/postgresql {
daily
rotate 3
compress
delaycompress
missingok
notifempty
create 644 root root
}
Every night, I would look at my rails logs and it would always be bigger -- i.e. it didn't seem like the logs were getting rotated ...
myuser@myproject:~$ ls -al /home/rails/myproject/log
total 4574368
drwxr-xr-x 2 rails rails 4096 May 30 12:04 .
drwxr-xr-x 15 rails rails 4096 May 30 12:03 ..
-rw-rw-r-- 1 rails rails 14960 Jun 1 22:39 development.log
-rw-rw-r-- 1 rails rails 0 Oct 22 2016 .keep
-rw-r--r-- 1 rails rails 4523480004 Jun 22 10:19 production.log
-rw-rw-r-- 1 rails rails 156358087 Jun 22 10:19 sidekiq.log
-rw-rw-r-- 1 rails rails 54246 Apr 10 14:34 test.log
When I run the command manually, I see that some of the logs seem to get rotated ...
myuser@myproject:~$ sudo logrotate /etc/logrotate.conf
myuser@myproject:~$ ls -al /home/rails/myproject/log
total 4570288
drwxr-xr-x 2 rails rails 4096 Jun 22 10:22 .
drwxr-xr-x 15 rails rails 4096 May 30 12:03 ..
-rw-rw-r-- 1 rails rails 0 Jun 22 10:22 development.log
-rw-rw-r-- 1 rails rails 14960 Jun 1 22:39 development.log.1
-rw-rw-r-- 1 rails rails 0 Oct 22 2016 .keep
-rw-r--r-- 1 rails rails 0 Jun 22 10:22 production.log
-rw-r--r-- 1 rails rails 4523505906 Jun 22 10:23 production.log.1
-rw-rw-r-- 1 rails rails 156369048 Jun 22 10:23 sidekiq.log
-rw-rw-r-- 1 rails rails 54246 Apr 10 14:34 test.log
How do I figure out why my rails logs are not rotated nightly? Note that other logs in the system seem to be. Above, I included my postgres configuration, and when I look at the logs there, seem to be rotating normally ...
myuser@myproject:~$ ls -al /var/log/postgresql
total 1832
drwxrwxr-t 2 root postgres 4096 May 2 20:42 .
drwxr-xr-x 13 root root 4096 Jun 22 10:22 ..
-rw-r----- 1 postgres adm 1861361 Jun 22 10:14 postgresql-9.6-main.log
Thanks, - Dave
Edit: Putting the configuration in a separate file didn't seem to do anything. Below is my configuration and also the logs that didn't appear to get rotated ...
myuser@myapp:~$ sudo cat /etc/logrotate.d/myapp
[sudo] password for myuser:
/home/rails/myapp/log/*.log {
daily
missingok
compress
notifempty
rotate 12
create
delaycompress
missingok
su rails rails
}
Here are the logs. Doesn't appear anything happened ...
myuser@myapp:~$ ls -al /home/rails/myapp/log
total 4635956
drwxr-xr-x 2 rails rails 4096 Jun 22 10:22 .
drwxr-xr-x 15 rails rails 4096 May 30 12:03 ..
-rw-rw-r-- 1 rails rails 0 Jun 22 10:22 development.log
-rw-rw-r-- 1 rails rails 14960 Jun 1 22:39 development.log.1
-rw-rw-r-- 1 rails rails 0 Oct 22 2016 .keep
-rw-r--r-- 1 rails rails 0 Jun 22 10:22 production.log
-rw-r--r-- 1 rails rails 4546785231 Jun 24 12:12 production.log.1
-rw-rw-r-- 1 rails rails 200336693 Jun 24 12:51 sidekiq.log
-rw-rw-r-- 1 rails rails 54246 Apr 10 14:34 test.log
/etc/logrotate.d
rather than using/etc/logrotate.conf
, does logrotate.conf still have its original content too?.
and..
files refer to the directory/var/log/postgresql
, and the parent directory/var/log
, you see these because you're using the-a
switch onls
. If they were rotating you would have filespostgrsql-9.6-main.log
,postgrsql-9.6-main.log.1
andpostgrsql-9.6-main.log.2.gz
./etc/logrotate.conf
that needs to be there, like rotating/var/log/wtmp
and/var/log/btmp
. I've just noticed the section labelled#system-specific logs...
so suppose there's no harm in appending logrotate instructions. I find it easier having specific files, for ease of management. The answer below should solve the problem I think you're having.