Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added CHRONY_EXTRA option for additional configuration #1

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ NTP_SERVERS="ntp1.aliyun.com,ntp2.aliyun.com,ntp3.aliyun.com,ntp4.aliyun.com"

# local (offline)
NTP_SERVER="127.127.1.1"

# ptp source (pass device to container)
CHRONY_EXTRA=refclock PHC /dev/ptp0
```

If you're interested in a public list of stratum 1 servers, you can have a look at the following list.
Expand Down
18 changes: 18 additions & 0 deletions assets/startup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

DEFAULT_NTP="time.cloudflare.com"
DEFAULT_EXTRA=""
CHRONY_CONF_FILE="/etc/chrony/chrony.conf"

# confirm correct permissions on chrony run directory
Expand Down Expand Up @@ -32,6 +33,11 @@ if [ -z "${NTP_SERVERS}" ]; then
NTP_SERVERS="${DEFAULT_NTP}"
fi

# CHRONY_EXTRA environment variable is not present, so populate with default server
if [ -z "${CHRONY_EXTRA}" ]; then
CHRONY_EXTRA="${DEFAULT_EXTRA}"
fi

# LOG_LEVEL environment variable is not present, so populate with chrony default (0)
# chrony log levels: 0 (informational), 1 (warning), 2 (non-fatal error) and 3 (fatal error)
if [ -z "${LOG_LEVEL}" ]; then
Expand Down Expand Up @@ -61,6 +67,18 @@ for N in $NTP_SERVERS; do
fi
done

{
echo
echo "# Extra config provided by CHRONY_EXTRA environment variables."
} >> ${CHRONY_CONF_FILE}
IFS=","
for N in $CHRONY_EXTRA; do
# strip any quotes found before or after ntp server
N_CLEANED=${N//\"}

echo ${N_CLEANED} >> ${CHRONY_CONF_FILE}
done

# final bits for the config file
{
echo
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ services:
restart: always
ports:
- 123:123/udp
# devices:
# - "/dev/ptp0:/dev/ptp0"
environment:
- NTP_SERVERS=time.cloudflare.com
- LOG_LEVEL=0
# - CHRONY_EXTRA=refclock PHC /dev/ptp0 offset 0
# - NOCLIENTLOG=true
3 changes: 2 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ function start_container() {
--restart=always \
--publish=123:123/udp \
--env=NTP_SERVERS=${NTP_SERVERS} \
--env=NOCLIENTLOG=${NOCLIENTLOG} \
--env=NOCLIENTLOG=${NOCLIENTLOG} \
--env=LOG_LEVEL=${LOG_LEVEL} \
--env=CHRONY_EXTRA=${CHRONY_EXTRA} \
--read-only=true \
--tmpfs=/etc/chrony:rw,mode=1750 \
--tmpfs=/run/chrony:rw,mode=1750 \
Expand Down
5 changes: 5 additions & 0 deletions vars
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ LOG_LEVEL=0

# (optional) additional docker run options you may want
DOCKER_OPTS=""

# (optional) define additional chrony config
# Each line must: be comma deliminated
# CHRONY_EXTRA="# Set reference clock to PTP source,refclock PHC /dev/ptp0 offset 0"
CHRONY_EXTRA=""