12

I have a logfile owner by the 'apache' user that I would like to rotate with logrotate.

I would like to do that by running logrotate as a different user, say 'web' using the copytruncate strategy.

That fails with this error:

error: error setting owner of ./logfile.log.1: Operation not permitted

But only because logrotate tries to change the owner of the new file to the owner of the rotated file, ie apache. But I dont care about the new files having the same owner, if logrotate would create copies with 'web' as owner that would be fine and then it could work fine.

So is there any way to stop logrotate from changing the owner of the copied file?

1
  • 1
    Leaving this for posterity: using postscript and chown "$1" is probably not appropriate here because it won't prevent logrotate from failing to set the owner. – David Lord Jul 23 '15 at 0:47
10

I use the create directive in my /etc/logrotate.d/ files. Example:

create 0664 www-data www-data
2

create will probably do what you describe in the last sentence of your question, but this option is incompatible with copytruncate, which you also say you want to use.

1

I resolved same problem with postrotate and prerotate options:

/opt/bars/web_edu/var/log/nginx*.log {
        su web_edu web_edu
        daily
    compress
        missingok
        rotate 30
        dateext
        notifempty
        create 0644 web_edu web_edu
        sharedscripts
        prerotate
                chown web_edu:web_edu /opt/bars/web_edu/var/log/nginx*.log
        endscript
        postrotate
                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid` || true
                chown web_edu:web_edu /opt/bars/web_edu/var/log/nginx*.gz
                chown web_edu:web_edu /opt/bars/web_edu/var/log/nginx*.log
        endscript
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.