Skip to content

Commit 40cde09

Browse files
committed
chrony: make default pools optional
Move the baked-in `resinio.pool.ntp.org` entries out of `chrony.conf` and into `balena-ntp-config` so they can be suppressed by setting `ntpServers` to "null". Custom config entries keep using `added_config.sources` while defaults now live in `default.sources`, matching the DHCP split. The README now explains the unset/"null"/custom behaviors. Fixes: #3680 Change-type: patch Signed-off-by: Shaun Cooley <365611+shaunco@users.noreply.github.com>
1 parent a5bae83 commit 40cde09

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,11 @@ The behavior of balenaOS can be configured by setting the following keys in the
193193

194194
### ntpServers
195195

196-
(string) A space-separated list of NTP servers to use for time synchronization. Defaults to `resinio.pool.ntp.org` servers:
196+
(string) A space-separated list of NTP servers to use for time synchronization.
197197

198-
- `0.resinio.pool.ntp.org`
199-
- `1.resinio.pool.ntp.org`
200-
- `2.resinio.pool.ntp.org`
201-
- `3.resinio.pool.ntp.org`
198+
- When `ntpServers` is not defined, or empty, the following default pools are added to the chrony configuration: `0.resinio.pool.ntp.org`, `1.resinio.pool.ntp.org`, `2.resinio.pool.ntp.org`, `3.resinio.pool.ntp.org`.
199+
- When `ntpServers` is "null" (a string), no default pools are added. This is useful when your network provides its own NTP servers via DHCP Option 42 or when no external NTP access is desired.
200+
- When `ntpServers` is defined and not "null", only the listed servers are added (in addition to any servers supplied through DHCP Option 42).
202201

203202
### dnsServers
204203

meta-balena-common/recipes-connectivity/balena-ntp-config/balena-ntp-config/balena-ntp-config

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ set -e
99

1010
SERVER_DIR=/run/chrony
1111
SERVER_FILE=${SERVER_DIR}/added_config.sources
12+
DEFAULT_SERVER_FILE=${SERVER_DIR}/default.sources
13+
DEFAULT_NTP_SERVERS="0.resinio.pool.ntp.org 1.resinio.pool.ntp.org 2.resinio.pool.ntp.org 3.resinio.pool.ntp.org"
1214

1315
if [ ! -f "$CONFIG_PATH" ]; then
1416
echo "balena-ntp-config: $CONFIG_PATH does not exist."
@@ -25,12 +27,26 @@ fi
2527
if [ -f "$SERVER_FILE" ]; then
2628
rm -f $SERVER_FILE
2729
fi
30+
if [ -f "$DEFAULT_SERVER_FILE" ]; then
31+
rm -f $DEFAULT_SERVER_FILE
32+
fi
2833

29-
if [ ! -z "$NTP_SERVERS" ]; then
30-
echo "Adding NTP sources (config.json)"
31-
for server in ${NTP_SERVERS}; do
32-
echo "pool $server iburst minpoll 14 maxpoll 14 maxsources 1" >> $SERVER_FILE
34+
add_servers() {
35+
local target_file=$1
36+
local servers=$2
37+
for server in $servers; do
38+
echo "pool $server iburst minpoll 14 maxpoll 14 maxsources 1" >> "$target_file"
3339
done
40+
}
41+
42+
if [ "$NTP_SERVERS" = "null" ]; then
43+
echo "balena-ntp-config: Default NTP sources disabled via config.json"
44+
elif [ -n "$NTP_SERVERS" ]; then
45+
echo "Adding NTP sources (config.json)"
46+
add_servers "$SERVER_FILE" "$NTP_SERVERS"
47+
else
48+
echo "balena-ntp-config: Using default NTP sources"
49+
add_servers "$DEFAULT_SERVER_FILE" "$DEFAULT_NTP_SERVERS"
3450
fi
3551

3652
# Always update the sources as they may have been added or removed.

meta-balena-common/recipes-core/chrony/files/chrony.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
pool 0.resinio.pool.ntp.org iburst minpoll 14 maxpoll 14 maxsources 1
2-
pool 1.resinio.pool.ntp.org iburst minpoll 14 maxpoll 14 maxsources 1
3-
pool 2.resinio.pool.ntp.org iburst minpoll 14 maxpoll 14 maxsources 1
4-
pool 3.resinio.pool.ntp.org iburst minpoll 14 maxpoll 14 maxsources 1
51
sourcedir /run/chrony
62
driftfile /var/lib/chrony/drift
73
maxupdateskew 100

0 commit comments

Comments
 (0)