diff options
Diffstat (limited to 'recipes-support/ntp/files/ntpdate')
| -rwxr-xr-x | recipes-support/ntp/files/ntpdate | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/recipes-support/ntp/files/ntpdate b/recipes-support/ntp/files/ntpdate new file mode 100755 index 0000000000..784b029ad5 --- /dev/null +++ b/recipes-support/ntp/files/ntpdate | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=/sbin:/bin:/usr/bin | ||
| 4 | |||
| 5 | test -x /usr/bin/ntpdate || exit 0 | ||
| 6 | |||
| 7 | if test -f /etc/default/ntpdate ; then | ||
| 8 | . /etc/default/ntpdate | ||
| 9 | else | ||
| 10 | NTPSERVERS="pool.ntp.org" | ||
| 11 | fi | ||
| 12 | |||
| 13 | test -n "$NTPSERVERS" || exit 0 | ||
| 14 | |||
| 15 | # This is a heuristic: The idea is that if a static interface is brought | ||
| 16 | # up, that is a major event, and we can put in some extra effort to fix | ||
| 17 | # the system time. Feel free to change this, especially if you regularly | ||
| 18 | # bring up new network interfaces. | ||
| 19 | if [ "$METHOD" = static ]; then | ||
| 20 | OPTS="-b" | ||
| 21 | fi | ||
| 22 | |||
| 23 | if [ "$METHOD" = loopback ]; then | ||
| 24 | exit 0 | ||
| 25 | fi | ||
| 26 | |||
| 27 | ( | ||
| 28 | |||
| 29 | LOCKFILE=/var/lock/ntpdate | ||
| 30 | |||
| 31 | # Avoid running more than one at a time | ||
| 32 | if [ -x /usr/bin/lockfile-create ]; then | ||
| 33 | lockfile-create $LOCKFILE | ||
| 34 | lockfile-touch $LOCKFILE & | ||
| 35 | LOCKTOUCHPID="$!" | ||
| 36 | fi | ||
| 37 | |||
| 38 | if /usr/bin/ntpdate -s $OPTS $NTPSERVERS 2>/dev/null; then | ||
| 39 | if [ "$UPDATE_HWCLOCK" = "yes" ]; then | ||
| 40 | hwclock --systohc || : | ||
| 41 | fi | ||
| 42 | fi | ||
| 43 | |||
| 44 | if [ -x /usr/bin/lockfile-create ] ; then | ||
| 45 | kill $LOCKTOUCHPID | ||
| 46 | lockfile-remove $LOCKFILE | ||
| 47 | fi | ||
| 48 | |||
| 49 | ) & | ||
