GNU/Linux >> Linux の 問題 >  >> Linux

Logrotateに開いているファイルを無視するように指示する方法は?

少し検索しましたが、何も見つかりません。 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に依存する バージョンがありますが、このように動作する/動作しないバージョンに関するドキュメントが見つかりません。


Linux
  1. ファイルがすでに両側にある場合にディレクトリ構造を同期する方法はありますか?

  2. 古いログファイルをクリーンアップするコマンド?

  3. Logrotateを使用してログファイルを管理する方法

  1. /var/log ディレクトリにある 20 個の Linux ログ ファイル

  2. Unix/Linux で 2 つのファイルの内容が同じかどうかを確認する最速の方法は?

  3. Subversionでディレクトリ/ファイルを無視するには?

  1. プロセスごとに開いているファイルをカウントする

  2. cron ジョブを使用してログ ファイルを削除する

  3. nginx最大オープンファイルを設定するには?