Sysntpd issue + unable get ntptime

I am using Openwrt 18.06-SNAPSHOT with BusyBox v1.28.3

The system is configured to get clock over NTP using "ntpd" package. It has been working fine until today.

Issue 1:

During debugging I found that system is generating the error "sysntpd not found".
What could be the reason for this error? How can I fix this?

Issue 2:

The rc.local file has the following:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing
/etc/init.d/cvScript start
/etc/init.d/sysntpd disable
/etc/init.d/ntpd enable
/etc/init.d/ntpd start

exit 0

When I run the same commands on the command line it works fine with no problem.

Note:
The system connects with the server and updates data to it after reboot.
When I perform "opkg update", I get the following:

 * opkg_download: Failed to download http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/telephony/Packages.gz, wget returned 4.
 * opkg_download: Check your network settings and connectivity.

I am unable to ping the server from the system. I am not sure how it is unable to ping the server it is sending the data to.

"opkg update" and "ntpd" used to work fine before. Is it because of firewall setting?

Thanks

readlink -f $(type -p ntpd)

System output for the above command is

/sbin/ntpd.

1 Like

You need to run ./sysntpd start in /etc/init.d directory or /etc/init.d/sysntpd start

System generates the error

sysntpd not found

What does the command returns
cat /etc/init.d/sysntpd

#!/bin/sh /etc/rc.common
# Copyright (C) 2011 OpenWrt.org

START=98

USE_PROCD=1
PROG=/usr/sbin/ntpd
HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug

get_dhcp_ntp_servers() {
	local interfaces="$1"
	local filter="*"
	local interface ntpservers ntpserver

	for interface in $interfaces; do
		[ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'"
	done

	ntpservers=$(ubus call network.interface dump | jsonfilter -e "@.interface[$filter]['data']['ntpserver']")

	for ntpserver in $ntpservers; do
		local duplicate=0
		local entry
		for entry in $server; do
			[ "$ntpserver" = "$entry" ] && duplicate=1
		done
		[ "$duplicate" = 0 ] && server="$server $ntpserver"
	done
}

validate_ntp_section() {
	uci_validate_section system timeserver "${1}" \
		'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' 'use_dhcp:bool:1' 'dhcp_interface:list(string)'
}

start_service() {
	local server enabled enable_server use_dhcp dhcp_interface peer

	validate_ntp_section ntp || {
		echo "validation failed"
		return 1
	}

	[ $enabled = 0 ] && return

	[ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface"

	[ -z "$server" -a "$enable_server" = "0" ] && return

	procd_open_instance
	procd_set_param command "$PROG" -n -N
	[ "$enable_server" = "1" ] && procd_append_param command -l
	[ -x "$HOTPLUG_SCRIPT" ] && procd_append_param command -S "$HOTPLUG_SCRIPT"
	for peer in $server; do
		procd_append_param command -p $peer
	done
	procd_set_param respawn
	procd_close_instance
}

service_triggers() {
	local script name use_dhcp

	script=$(readlink -f "$initscript")
	name=$(basename ${script:-$initscript})

	procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload

	config_load system
	config_get use_dhcp ntp use_dhcp 1

	[ $use_dhcp = 1 ] && {
		local dhcp_interface
		config_get dhcp_interface ntp dhcp_interface

		if [ -n "$dhcp_interface" ]; then
			for n in $dhcp_interface; do
				procd_add_interface_trigger "interface.*" $n /etc/init.d/$name reload
			done
		else
			procd_add_raw_trigger "interface.*" 1000 /etc/init.d/$name reload
		fi
	}

	procd_add_validation validate_ntp_section
}

/etc/init.d/ is not part of $PATH. You either prefix it with ./ or you specify the full path.

3 Likes

Thanks. Running from the same directory works.

Don't know why it happens only with this file in the directory "/etc/init.d/".

"ntptime" still returns error code 5.

The rc.local file has the following:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing
/etc/init.d/cvScript start
/etc/init.d/sysntpd disable
/etc/init.d/ntpd enable
/etc/init.d/ntpd start

exit 0

The system does not obtain time from network after reboot. It gives me error code 5 when I execute "ntptime".

When I run all the commands in the command line with prefix "/etc/init.d", the "ntptime" works fine and the return code is 0.

Why are you doing this at each startup?
Normally you do this once and that's it.

3 Likes

Its because the system does not have a real-time clock / battery.

The system powers on through 5v adapter and the script runs after every reboot.

Resolved the ntp issue by moving the application script startup to the end of rc.local file.

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing

#/etc/init.d/cvScript start
/etc/init.d/sysntpd disable
/etc/init.d/ntpd enable
/etc/init.d/ntpd start

/etc/init.d/cvScript start

exit 0

I was able to see the ntp process running using "ps" command before and after the change was made. Cannot understand how this change made it work.

I updated the application to previous stable release to check if something in the application affected it, but that did not help. Only moving the application script to the end of "rc.local" makes the ntp time work.

Looks like something is taking time to initialize and in the meantime the "ntp" times out.
May be some file configuration was changed or corrupted/ kernel was updated. Could someone throw some light on this issue?

"opkg update" is still not working.

What happens if you change your rc.local to the following:

#/etc/init.d/cvScript start
#/etc/init.d/sysntpd disable
#/etc/init.d/ntpd enable
#/etc/init.d/ntpd start

/etc/init.d/cvScript start

exit 0

?

2 Likes
/etc/init.d/cvScript enable
sed -i -e "/^\/etc\/init\.d/s/^/#/" /etc/rc.local
1 Like

Thank you. I tried your suggestion. The unit does not obtain "ntp tine" from the NTP server but the application starts up and works fine. It communicates correctly with the server.
"opkg update" is still not working.

I tried

/etc/init.d/cvScript enable

The output is:

root@OpenWrt:~# /etc/init.d/cvScript enable
Usage: /etc/init.d/cvScript {start|stop|status}
1 Like
ln -f -s ../init.d/cvScript /etc/rc.d/S97cvScript
1 Like

Thanks @tmomas, vgaetera. I tried, still the unit does not get the time from NTP server but the application starts up fine.

Also, I found some subtle difference between the kernel on this unit and the ones that I have used before. In the root folder, there are some userspace folders which were not therebefore.

As the kernel is done by third-party I have referred it to them on the basis that it was working before and the application has not changed.

Thanks for helping me troubleshoot this issue.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.