Trochu jsem hledal a nic nenašel. Nechci logrotate
dotknout se aktuálně otevřených souborů. Myslel jsem, že něco udělám s lsof
ale neviděl jsem způsob, jak přimět některý ze skriptů k přerušení operace. Nějaké nápady?
Přijatá odpověď:
Pokud máte nosharedscripts
set (výchozí) a prerotate
skript se ukončí s chybou, v dotčeném souboru protokolu nebude provedena žádná další akce*.
Takže teoreticky byste mohli mít něco jako (varování, netestováno):
/var/log/application.log {
nosharedscripts
prerotate
logfile=$1
lsof $logfile >/dev/null
exit $?
endscript
...
}
takže pokud lsof
nemůže najít žádné procesy pomocí $logfile
otevřít, prerotate
skript se ukončí s 1
a logrotate
neprovede s tímto protokolem žádnou akci.
*Z logrotate(8)
manuálová stránka na 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.
To může být závislý na vašem logrotate
verze, ale nemohu najít žádnou dokumentaci o tom, které verze se takto chovají/nechovají.