OpenWrt Forum Archive

Topic: How to sychronize time at startup using ntpd

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Setting the date manually using date works but get's lost with a reboot. How do use ntpd for time synchronization in OpenWrt?

shogun@l0calh0st:~$ date
Thu Jan  1 00:07:25 UTC 1970

shogun@l0calh0st:~$ cat /etc/config/timeserver
config timeserver
        option hostname ptbtime1.ptb.de
#       option interface        wan

config timeserver
        option hostname time-a.nist.gov

config timeserver
        option hostname ntp.xs4all.nl

config timeserver
        option hostname ptbtime2.ptb.de

config timeserver
        option hostname time-b.nist.gov

shogun@l0calh0st:~$ cat /etc/init.d/sysntpd
#!/bin/sh /etc/rc.common
# Copyright (C) 2011 OpenWrt.org

START=98

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
SERVICE_PID_FILE=/var/run/sysntpd.pid

start() {
        [ -x $PROG ] || return 1

        local peers

        getpeers() {
                config_get peers "$1" server
        }

        config_load system
        config_foreach getpeers timeserver

        if [ -n "$peers" ]; then
                local peer
                local args="-n"
                for peer in $peers; do
                        append args "-p $peer"
                done

                service_start /usr/sbin/ntpd $args
        fi
}

stop() {
        service_stop /usr/sbin/ntpd
}

shogun@l0calh0st:~$ sudo ntpd
BusyBox v1.19.3 (2011-11-26 15:20:28 GMT) multi-call binary.

Usage: ntpd [-dnqNwl] [-S PROG] [-p PEER]...

<output omitted>

ntpd on whiteRussian has no /etc/config/timeserver file at all.  Where did you get this ipkg?

The discussion might have continued from here.