
/etc/crontab
毎日 4:25 AM に cron ジョブが実行されるように、ファイルに次のエントリがあります。これはdaily
、このファイル内の唯一のエントリです。
25 4 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
私の内容は/etc/cron.daily/
次のとおりですlogrotate
:
# ls -l /etc/cron.daily/
...
-rwxr-xr-x 1 root root 377 Jan 21 2019 logrotate
logrotateの設定は以下のとおりです/etc/logrotate.d/
/var/log/remote/custom/*.log
{
rotate 180
daily
missingok
notifempty
compress
delaycompress
sharedscripts
# force rsyslog to refresh file descriptor
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
の内容を調べると /var/lib/logrotate/status
、ログファイルが午前 4 時 25 分ではなく午前 0 時にローテーションされていることがわかるのはなぜですか?
"/var/log/remote/custom/cust.log" 2020-11-4-0:0:39
オペレーティング システム:Ubuntu 20.04 LTS
カーネル:Linux 5.4.0-40-generic
答え1
anacron が /etc/cron.daily (およびその他) を評価するタイミングを見つける /etc/anacrontab を見落としているようです。
また、私が systemd を避けている理由の 1 つは、/etc/cron.daily/logrotate の最初の行を確認することです。
# less -X /etc/cron.daily/logrotate
#!/bin/sh
# skip in favour of systemd timer
if [ -d /run/systemd/system ]; then
exit 0
fi
答え2
のためにデビアンユーザーは、6.25(/etc/crontab)で実行されていると思うかもしれませんが、最近のバージョンでは00.00で実行されており、システム!
古い /etc/crontab:
25 6 * * * ルートテスト -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
systemd の実行時間を変更する場合は、このファイルを編集する必要があります。 /etc/systemd/system/timers.target.wants/logrotate.timer
デフォルトでは次のようになります:
[Timer]
OnCalendar=daily
毎日6.20に実行したい場合:
[Timer]
OnCalendar=*-*-* 6:20
(その後システムを再起動しましたが、それが必要かどうかはわかりません!)
答え3
編集するときは十分に注意してください/etc/systemd/system/timers.target.wants/logrotate.timer
。このファイルは へのシンボリック リンクです/lib/systemd/system/logrotate.timer
。
ファイルが誤ってシンボリック リンクから通常のファイルに変更された場合、タイマーは無視されます。これは、組み込みシステムのインストール スクリプトの一部として (たとえば) sed を使用してこのファイルを編集した場合に発生します。なぜ私が知っているのか、私に聞いてください。