wiki:TipAndDoc/network/ntp

Version 4 (modified by mitty, 15 years ago) (diff)

--

ntpdate

ntpd

hardware clockのsyncについて

CentOS 5

起動時

  • /etc/sysconfig/ntpd
    # Set to 'yes' to sync hw clock after successful ntpdate
    SYNC_HWCLOCK=yes
    
  • /etc/ntp/step-tickers
    • このファイルにホストが羅列されている場合、ntpd起動前にntpdateでupdateする
  • /etc/init.d/ntpd
    • boot時に実行されるスクリプトでは、以下のような流れになっている
      echo -n $"$prog: Synchronizing with time server: "
      /usr/sbin/ntpdate $dropstr -s -b $NTPDATE_OPTIONS $tickers &>/dev/null
      
      [ "$SYNC_HWCLOCK" = "yes" ] && sync_hwclock
      
    • sync_hwclock() は以下のようになっている
      action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
      
    • $CLOCKFLAGSは「--systohc」の他、環境に合わせてUTCなどを指定する引数がセットされている。
ログ
  • 以下のようなログが画面に表示される
    ntpd: Synchronizing with time server:                      [  OK  ]
    Syncing hardware clock to system time                      [  OK  ]
    Starting ntpd:                                             [  OK  ]
    

終了時

  • shutdown時はH/W clockとの同期は行ってない模様。

Ubuntu

起動時

  • 以下の二つのスクリプトがまず呼ばれる
    • /etc/rcS.d/S08hwclockfirst.sh
    • /etc/rcS.d/S11hwclock.sh
    • 中身は以下を除いてほぼ同一
      FIRST=yes	# debian/rules sets this to 'yes' when creating hwclockfirst.sh
      
    • boot時は、以下のコマンドにより「H/W clockからSystem clockへ」時刻がコピーされる
      if /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
      
  • その後、「/etc/rcS.d/S40networking」ででeth0などが起動されるが、この際以下のスクリプトが実行される。
    • /etc/network/if-up.d/ntpdate
      invoke-rc.d --quiet ntp stop || true
      /usr/sbin/ntpdate-debian -s $OPTS 2>/dev/null
      invoke-rc.d --quiet ntp start || true
      
    • このため、rcSののちにランレベル毎のスクリプトである「/etc/rc3.d/S23ntp」とは別にntpdがstart stopされる。このスクリプトはntpdパッケージとは別になっている。
      $ dpkg -S /etc/network/if-up.d/ntpdate
      ntpdate: /etc/network/if-up.d/ntpdate
      
    • また、「/etc/rc3.d/S23ntp」ではntpdが起動される以上のことは行われない

終了時

  • shutdown/reboot時は、/etc/rc0.d/K25hwclock.sh(あるいは/rc6.d/)によって、H/W clockがSystem clockによって上書きされる。
    if /sbin/hwclock --systohc $GMT $HWCLOCKPARS $BADYEAR; then
    

Attachments (5)

Download all attachments as: .zip