Ich habe ein bisschen gesucht und nichts gefunden. Ich möchte logrotate
nicht um Dateien zu berühren, die derzeit geöffnet sind. Ich dachte daran, etwas mit lsof
zu machen aber ich sah keine Möglichkeit, eines der Skripte dazu zu bringen, eine Operation abzubrechen. Irgendwelche Ideen?
Akzeptierte Antwort:
Wenn Sie nosharedscripts
haben set (Standard) und prerotate
Skript mit einem Fehler beendet wird, wird die betroffene Protokolldatei nicht weiter bearbeitet*.
Theoretisch könnten Sie also so etwas haben wie (Warnung, ungetestet):
/var/log/application.log {
nosharedscripts
prerotate
logfile=$1
lsof $logfile >/dev/null
exit $?
endscript
...
}
also wenn lsof
kann keine Prozesse mit $logfile
finden öffnen, das prerotate
Skript wird mit 1
beendet und logrotate
wird keine Aktion für dieses Protokoll ausführen.
*Aus logrotate(8)
Manpage auf linux.die.net:
nosharedscripts
Run prerotate and postrotate scripts for every log file which is rotated
(this is the default, and overrides the sharedscripts option). The absolute
path to the log file is passed as first argument to the script. If the
scripts exit with error, the remaining actions will not be executed for the
affected log only.
...
prerotate/endscript
The lines between prerotate and endscript (both of which must appear on
lines by themselves) are executed (using /bin/sh) before the log file is
rotated and only if the log will actually be rotated. These directives may
only appear inside a log file definition. Normally, the absolute path to
the log file is passed as first argument to the script. If sharedscripts is
specified, whole pattern is passed to the script. See also postrotate. See
sharedscripts and nosharedscripts for error handling.
Dies kann von Ihrem logrotate
abhängig sein Version, aber ich kann keine Dokumentation darüber finden, welche Versionen sich so verhalten / nicht.