Add optional GPS reference clock via gpsd#22
Open
tillo wants to merge 1 commit into
Open
Conversation
Mirrors the existing PTP0 opt-in pattern. When `GPS_DEVICE` is set and the device exists, the entrypoint spawns gpsd in background pointed at that serial UART and appends a `refclock SHM 0 refid GPS` line to chrony.conf. Optional `GPS_BAUD`, `GPS_REFCLOCK_OFFSET` knobs, and `GPS_PPS=true` to also consume PPS samples via SHM segment 1. When unset, gpsd is installed but never started — non-GPS users see only the Alpine package added to the image (a few MB), no runtime effect. Used in production on a Mediatek MT7988 + USB-UART GPS to serve an NTP-Pool stratum-1 from the same chronyd image. The pattern was previously maintained as an out-of-tree fork; upstreaming so other operators with a serial GPS can run a stratum-1 from this image without a custom build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds optional GPS reference-clock support, mirroring the existing PTP0 opt-in pattern.
Motivation
Several of us run a stratum-1 NTP-Pool / OpenNIC server backed by a serial GPS receiver (USB UART GPS dongle, hat-mounted GPS on a router/SBC, etc.). The image already has all the chrony machinery for a serial refclock, so the only missing piece is bringing up
gpsdagainst the device and adding arefclock SHM ...line tochrony.conf. That's what this PR does — about ten lines in the entrypoint.I've been maintaining it as an out-of-tree fork for a year; upstreaming so anyone else with a serial GPS can run a stratum-1 from this image without a custom build.
Behaviour
Opt-in via a single env var, same shape as
ENABLE_NTS/ENABLE_SYSCLK/the PTP0 device-passthrough:When
GPS_DEVICEis set and the device exists, the entrypoint launchesgpsd -N -F /run/chrony/gpsd.sock -s ${GPS_BAUD} ${GPS_DEVICE}in background and appendsrefclock SHM 0 refid GPS offset … precision 1e-1tochrony.conf. WithGPS_PPS=truea secondrefclock SHM 1 refid PPS precision 1e-7 preferline is added — useful for receivers whose PPS pin is wired through and gpsd is configured to publish PPS samples on SHM segment 1.When unset,
gpsdis installed but never started.Image-size impact for non-GPS users
gpsdis added to theapk addline so the image grows by a few MB regardless of whether GPS is enabled. I considered making it a separate build target /Dockerfile.gpsso the default image stays unchanged, but the unified pattern (ENABLE_NTS,ENABLE_SYSCLK, PTP0 device-passthrough — all single-image, runtime-opt-in) seemed more in line with how the rest of the image works. Happy to split into agpsd-tagged variant instead if you prefer.Permissions note
The serial device must be readable by the
chronyuser. Documented in the README — easiest ischmod g+r /dev/ttyUSB0+chown :dialout /dev/ttyUSB0on the host plusgroup_add: [dialout]on the container; or run the container as root.Tested
In production on a Mediatek MT7988 (BPI-R4) + USB-UART GPS, feeding an NTP-Pool stratum-1 server. The fork has been running this code path since April; the recent improvement in this PR (the
[ -e "${GPS_DEVICE}" ]guard) is to make a missing/unplugged GPS not abortchronydso the container still serves stratum-2 fromNTP_SERVERSuntil the hardware is replaced.