logrotate dreht sich nicht, Berechtigung als root-Benutzer verweigert

1630
Erich

Ich habe ein Problem, dass ich meinen Kopf nicht einwickeln kann. Ich habe auf einem Centos 7-Server einen Logrotate-Server eingerichtet, um meine App-Protokolle zu drehen.

Diese Datei befindet sich in /etc/cron.daily (ich habe sogar einen whoami hinzugefügt, um zu überprüfen, ob sie als root ausgeführt wird):

#!/bin/sh  whoami  /usr/sbin/logrotate -v /etc/logrotate.d/myapp EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 

Dies führt meine Logrotate-Konfiguration aus ...

"/opt/myapp/log/*.log" { daily create 644 root root rotate 5 size 20M copytruncate missingok notifempty compress } 

Hier ist mein Log-Verzeichnis ...

[root@server log]# ls -la total 97684 drwxr-xr-x. 3 root root 4096 Sep 28 12:41 . drwxr-xr-x. 5 root root 4096 Sep 27 20:57 .. -rw-r--r--. 1 root root 100015457 Sep 28 12:36 myapp.log 

Jedes Mal, wenn wir es manuell als root ausführen, wird das Protokoll gedreht ... aber wenn wir es durch cron ausführen, schlägt es fehl. Hier ist die Mail, die es sendet ...

From root@server Thu Sep 28 12:30:02 2017 Return-Path: <root@server> X-Original-To: root Delivered-To: root@server Received: by server (Postfix, from userid 0) id 9C82B419; Thu, 28 Sep 2017 12:30:02 -0500 (CDT) From: "(Cron Daemon)" <root@server> To: root@server Subject: Cron <root@server> run-parts /etc/cron.daily Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated Precedence: bulk X-Cron-Env: <XDG_SESSION_ID=10746> X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0> X-Cron-Env: <LANG=en_US.UTF-8> X-Cron-Env: <SHELL=/bin/bash> X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin> X-Cron-Env: <MAILTO=root> X-Cron-Env: <HOME=/root> X-Cron-Env: <LOGNAME=root> X-Cron-Env: <USER=root> Message-Id: <20170928173002.9C82B419@server> Date: Thu, 28 Sep 2017 12:30:01 -0500 (CDT) /etc/cron.daily/myapp:  root <<<<<<<<< whoami output reading config file /etc/logrotate.d/myapp Handling 1 logs rotating pattern: /opt/myapp/log/*.log 20971520 bytes (5 rotations) empty log files are not rotated, old logs are removed considering log /opt/myapp/log/myapp.log log needs rotating rotating log /opt/myapp/log/myapp.log, log->rotateCount is 5 error: error opening /opt/myapp/log/myapp.log: Permission denied set default create context 

Hat jemand jemals etwas davon oder hat irgendwelche Ideen, was dies verursachen könnte?

0

1 Antwort auf die Frage

0
Erich

Es stellte sich heraus, dass dies ein SELinux-Problem war. Der Dateikontext war nicht das, auf das Logrotate Zugriff hatte. Daher wurde ihm wiederholt der Zugriff verweigert.

Siehe hier für diese Antwort: SELinux fcontext