xref: /OK3568_Linux_fs/buildroot/package/ntp/S48sntp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2
3DAEMON="sntp"
4# sntp uses all the IPs resolved for the hostname (i.e. pool.ntp.org has 4).
5# It will try each until they either all timeout or time has been set. Thus
6# default to only providing one NTP pool host.
7SNTP_SERVERS="pool.ntp.org"
8# Step if time delta is greater then 128ms, otherwise slew
9SNTP_ARGS="-Ss -M 128"
10SNTP_KEY_CACHE="/tmp/kod"
11
12# shellcheck source=/dev/null
13[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
14
15start() {
16	printf 'Starting %s: ' "$DAEMON"
17	# Create key cache file to prevents warning that file is missing
18	touch $SNTP_KEY_CACHE
19	# shellcheck disable=SC2086 # we need the word splitting
20	/usr/bin/$DAEMON $SNTP_ARGS -K $SNTP_KEY_CACHE $SNTP_SERVERS
21	# sntp behavior
22	# - Does not background
23	# - Does not infinitely block
24	# - Time-out w/o network = ~2 sec
25	# - Time-out w/ network = ~5sec * # of servers
26	status=$?
27	if [ "$status" -eq 0 ]; then
28		echo "OK"
29	else
30		echo "FAIL"
31	fi
32	return "$status"
33}
34
35stop() {
36	echo "Nothing to do, $DAEMON is not a daemon."
37}
38
39restart() {
40	stop
41	sleep 1
42	start
43}
44
45reload() {
46	echo "Nothing to do, $DAEMON does not support reload."
47}
48
49case "$1" in
50	start|stop|restart|reload)
51		"$1";;
52	*)
53		echo "Usage: $0 {start|stop|restart|reload}"
54		exit 1
55esac
56