logrotate가 회전 된 로그 소유자를 변경하지 못하게하는 방법


9

logrotate로 회전하려는 'apache'사용자의 로그 파일 소유자가 있습니다.

다른 사용자로 logrotate를 실행하여 copytruncate 전략을 사용하여 'web'이라고 말하고 싶습니다.

이 오류로 실패합니다.

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

그러나 logrotate가 새 파일의 소유자를 회전 된 파일의 소유자, 즉 아파치로 변경하려고 시도하기 때문입니다. 그러나 logrotate가 소유자로 'web'을 사용하여 사본을 만들면 정상적으로 작동 할 수 있다면 동일한 소유자가있는 새 파일에 대해서는 신경 쓰지 않습니다.

그래서 logrotate가 복사 된 파일의 소유자를 변경하지 못하게하는 방법이 있습니까?


1
후손을 위해 이것을 남겨 두십시오 : logrotate가 소유자를 설정하지 못하는 것을 막지 않기 때문에 postscriptchown "$1"여기를 사용하는 것이 적절하지 않습니다.
David Lord

답변:


7

파일 에서 create지시문을 사용 /etc/logrotate.d/합니다. 예:

create 0664 www-data www-data

1

create질문의 마지막 문장에 설명 된 내용을 수행 할 수 있지만이 옵션은와 호환되지 않으며 copytruncate사용하고 싶다고 말합니다.


0

postrotate 및 prerotate 옵션과 동일한 문제를 해결했습니다.

/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
}
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.