7

Recently I've noticed that logrotate does not rotate my logs.

user1@host:~$ /usr/sbin/logrotate /home/user1/logrotate.conf -v gives me an error:

error: error setting owner of /home/logs/mylog.log.1 to uid 10111 and gid 10111: 
Operation not permitted
error: error creating output file /var/lib/logrotate/status.tmp:
Permission denied

That gid confuses me, as user1 is only a member of a group with different gid:

user1@host:~$ id
uid=10111(user1) gid=1001(mygroup) groups=1001(mygroup)

However, there's another group called user1, but, as I mentioned, actual user user1 is not its member:

user1@host:~$ cat /etc/group | grep user1
user1:x:10111

It's something simple here, but I can't see it.

UPDATE: here's what logrotate.conf looks like:

/home/logs/*.log { rotate 7 daily copytruncate compress notifempty }

user1@host:~$ ls -al /home/logs/ -rw-r--r-- 1 user1 mygroup 190826983 Dec 18 06:05 mylog.log

hdf
  • 71
  • 1
  • 1
  • 4
  • does running `sudo logrotate -v /home/user1/logrotate.conf ` work for you? – the_velour_fog Dec 18 '15 at 04:50
  • can you please update your question by pasting the output of these commands `cat /home/user1/logrotate.conf` and also `ls -al ` (then format that code by highlighting and clicking the `{}` button) – the_velour_fog Dec 18 '15 at 05:58
  • are you showing us the usernames and pathnames etc -as they actually are - or are you changing them before you paste? they don't seem to match ... – the_velour_fog Dec 18 '15 at 06:21
  • @the_velour_fog yeah, my bad. should be ok now. – hdf Dec 18 '15 at 06:25

1 Answers1

1

You can try using logrotates create directive to set the permissions of the newly created log file. To use it you

/home/logs/*.log {
    rotate 7
    daily
    create 0777 user1 user1
    ^^^^^^^^^^^^^^^^^^^^^^
    copytruncate
    compress
    notifempty
 }

From man logrotate

 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 values as the original log file for the omitted attributes. This option can be disabled using the nocreate option.

the_velour_fog
  • 2,290
  • 5
  • 23
  • 34
  • but what this `user1` group has to do with all this stuff? – hdf Dec 18 '15 at 06:30
  • 1
    Quick note here, `create` should not be used together with `copytruncate` -- "When this option is used, the create option will have no effect, as the old log file stays in place." – Michael Butler Sep 08 '20 at 21:21