プロセスの実行中にログファイルを循環

プロセスの実行中にログファイルを循環

stdoutとstderrをログファイルに書き込むプロセスを実行しています/var/log/dragonturtle.log。ログファイルを循環し、プロセスを終了せずにプロセスに新しいログファイルを書き込むようにする方法はありますか?

現在何が起こっているのか(下記のlogrotate構成に応じて):

  • プロセスの書き込み/var/log/dragonturtle.log
  • ログローテーションの/var/log/dragonturtle.log移動/var/log/dragonturtle.log.1
  • 書き続けるプロセス/var/log/dragonturtle.log.1

私がしたいこと:

  • プロセスの書き込み/var/log/dragonturtle.log
  • /var/log/dragonturtle.log次へコピー:/var/log/dragonturtle.log.1
  • ログ回転切り捨て/var/log/dragonturtle.log
  • 書き続けるプロセス/var/log/dragonturtle.log

/etc/logrotate.d/dragonturtle:

/var/log/dragonturtle.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 644 dragonturtle dragonturtle
}

ベストアンサー1

logrotate説明するタスクを実行するオプションは、copytruncateこのオプションを既存のlogrotate構成に追加することです。以下は logrotate.conf マニュアルから抜粋したものです:

   copytruncate
          Truncate  the  original log file in place after creating a copy,
          instead of moving the old log file and optionally creating a new
          one,  It  can be used when some program can not be told to close
          its logfile and thus might continue writing (appending)  to  the
          previous log file forever.  Note that there is a very small time
          slice between copying the file and truncating it, so  some  log-
          ging  data  might be lost.  When this option is used, the create
          option will have no effect, as the old log file stays in  place.

おすすめ記事