少し検索しましたが、何も見つかりません。 logrotate
はしたくない 現在開いているファイルにタッチします。 lsof
で何かをしようと思っていました しかし、どのスクリプトでも操作を中止する方法がわかりませんでした。何かアイデアはありますか?
承認された回答:
nosharedscripts
がある場合 set(デフォルト)、およびprerotate
スクリプトはエラーで終了し、影響を受けるログファイルはそれ以上のアクションを実行しません*。
したがって、理論的には、(警告、テストされていない)のようなものがあります:
/var/log/application.log {
nosharedscripts
prerotate
logfile=$1
lsof $logfile >/dev/null
exit $?
endscript
...
}
したがって、lsof
$logfile
のプロセスが見つかりません 開いて、prerotate
スクリプトは1
で終了します 、およびlogrotate
そのログに対しては何のアクションも実行しません。
* logrotate(8)
から 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.
このかもしれません logrotate
に依存する バージョンがありますが、このように動作する/動作しないバージョンに関するドキュメントが見つかりません。