SVX日記
2021-08-16(Mon) anacronの挙動の細かすぎるところを伝えたい
これまで「かなり奇妙な挙動をするらしい」というだけの認識だったが、いざ知ってみれば、やっぱりかなり奇妙だった。詳細は「細かすぎて伝わらないanacronの挙動」という文書にあって、ものすごく参考になったのだが、やっぱり細かすぎて伝わりにくい……ので、ちょっと図化してみた。
まず、前提はこの「/etc/anacrontab」内の設定。着目点は「RANDOM_DELAY」の「45」と「START_HOURS_RANGE」の「3-22」と「delay in minutes」の「25」だ。
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days   delay in minutes   job-identifier   command
7	25	cron.weekly		nice run-parts /etc/cron.weekly    2:00                          2:30                          3:00                          3:30                          4:00
    |---------+---------+---------+---------+---------+---------|---------+---------+---------+---------+---------+---------+---------+----
     2:01 anacron 起動
      0 + 25 = 25 ----------> 2:26 (開始せず, RANGE 外)
      :
     33 + 25 = 58 -------------------------------------------> 2:59 (開始せず, RANGE 外)
     34 + 25 = 59 --------------------------------------------> 3:00 (開始)
      :
     45 + 25 = 70--------------------------------------------------------> 3:11 (開始)
     ^^   ^^                                                     3:01 anacron 起動
      |    +-- delay in minutes                                   0 + 25 = 25 ----------> 3:26 (開始)
      +-- RANDOM_DELAY                                            :
                                                                 45 + 25 = 70 -------------------------------------------------------> 4:11 (開始)
    |---------+---------+---------+---------+---------+---------|---------+---------+---------+---------+---------+---------+---------+----
    2:00                          2:30                          3:00                          3:30                          4:00
    開始する可能性のある範囲....................................oooooooooooo..............oooooooooooooooooooooooooooooooooooooooooooooo...3:00〜3:11 (2:01の回の anacron で起動された場合)、または
3:32〜4:11 (3:01の回の anacron で起動された場合)3:00〜3:11 (2:01の回の anacron で起動された場合)、または
3:26〜4:11 (3:01の回の anacron で起動された場合)xxx nn 02:01:01 xxxxxxx anacron[nnnnn]: Will run job `cron.weekly' in 59 min.
xxx nn 03:00:01 xxxxxxx anacron[nnnnn]: Job `cron.weekly' started
 
xxx nn 02:01:01 xxxxxxx anacron[nnnnn]: Will run job `cron.weekly' in 70 min.
xxx nn 03:11:01 xxxxxxx anacron[nnnnn]: Job `cron.weekly' started
 
xxx nn 03:01:01 xxxxxxx anacron[nnnnn]: Will run job `cron.weekly' in 25 min.
xxx nn 03:26:01 xxxxxxx anacron[nnnnn]: Job `cron.weekly' started
 
xxx nn 03:01:01 xxxxxxx anacron[nnnnn]: Will run job `cron.weekly' in 70 min.
xxx nn 04:11:01 xxxxxxx anacron[nnnnn]: Job `cron.weekly' started[ツッコミを入れる]