J'ai cherché un peu et je n'ai rien trouvé. Je ne veux pas logrotate pour toucher les fichiers actuellement ouverts. Je pensais faire quelque chose avec lsof mais je n'ai pas vu de moyen d'obtenir l'un des scripts pour abandonner une opération. Des idées ?
Réponse acceptée :
Si vous avez nosharedscripts set (par défaut), et le prerotate le script se termine avec une erreur, aucune autre action n'est entreprise sur le fichier journal concerné*.
Donc, en théorie, vous pourriez avoir quelque chose comme (avertissement, non testé) :
/var/log/application.log {
nosharedscripts
prerotate
logfile=$1
lsof $logfile >/dev/null
exit $?
endscript
...
}
donc si lsof ne trouve aucun processus avec $logfile ouvert, la prerotate le script se terminera avec 1 , et logrotate n'effectuera aucune action sur ce journal.
*Depuis le logrotate(8) page de manuel sur 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.
Cela peut être dépendant de votre logrotate version, mais je ne trouve aucune documentation sur les versions qui se comportent / ne se comportent pas de cette façon.