Repository navigation
Add Chrony stratum 1 time server (GPS/PPS via gpsd) #2680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jwklijnsma
wants to merge
7
commits into
community-scripts:main
Choose a base branch
from
jwklijnsma:feat/chrony-stratum1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
30ea8f2
Add Chrony stratum 1 time server (GPS/PPS via gpsd)
jwklijnsma 5ea53d3
Chrony: add stratum 2 and 3 modes
jwklijnsma 2410969
Chrony: address Proxmox test feedback
jwklijnsma 0527c64
Chrony: mark arm64 and Incus as supported
jwklijnsma ed275e2
Chrony: list arm64 and Incus in the JSON metadata
jwklijnsma 49e3e37
Chrony: default to stratum 2
jwklijnsma 873b4d4
Chrony: default container is unprivileged in the JSON metadata
jwklijnsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env bash | ||
| _CS_DEFAULT_URL="https://raw.githubusercontent.com/community-scripts/DevScripts/main" | ||
| _cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func" | ||
| source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func") | ||
|
|
||
| # Copyright (c) 2021-2026 community-scripts ORG | ||
| # Author: Jan Wiebe Klijnsma (jwklijnsma) | ||
| # License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE | ||
| # Source: https://chrony-project.org/ | ||
|
|
||
| APP="Chrony" | ||
| var_tags="${var_tags:-ntp;time;gps}" | ||
| var_cpu="${var_cpu:-1}" | ||
| var_ram="${var_ram:-512}" | ||
| var_disk="${var_disk:-4}" | ||
| var_os="${var_os:-debian}" | ||
| var_version="${var_version:-13}" | ||
| if [[ -z "${var_ntp_stratum:-}" ]] && command -v pveversion >/dev/null 2>&1; then | ||
| var_ntp_stratum=$(msg_menu "Choose the NTP stratum" \ | ||
| "2" "Stratum 2 - sync from public stratum 1 servers" \ | ||
| "3" "Stratum 3 - sync from the NTP pool or your own stratum 2" \ | ||
| "1" "Stratum 1 - GPS receiver (privileged, USB passthrough)") | ||
| fi | ||
| export var_ntp_stratum="${var_ntp_stratum:-2}" | ||
| if [[ "$var_ntp_stratum" == "1" ]]; then | ||
| var_unprivileged="${var_unprivileged:-0}" | ||
| else | ||
| var_unprivileged="${var_unprivileged:-1}" | ||
| fi | ||
| var_arm64="${var_arm64:-yes}" | ||
| export var_gps_device="${var_gps_device:-}" | ||
| export var_ntp_servers="${var_ntp_servers:-}" | ||
|
|
||
| header_info "$APP" | ||
| variables | ||
| color | ||
| catch_errors | ||
|
|
||
| function update_script() { | ||
| header_info | ||
| check_container_storage | ||
| check_container_resources | ||
|
|
||
| if [[ ! -f /etc/chrony/conf.d/server.conf ]]; then | ||
| msg_error "No ${APP} Installation Found!" | ||
| exit | ||
| fi | ||
|
|
||
| apt_update_safe | ||
| if ! apt list --upgradable 2>/dev/null | grep -qE '^(chrony|gpsd|gpsd-clients)/'; then | ||
| msg_ok "Chrony and gpsd are already up to date" | ||
| exit | ||
| fi | ||
|
|
||
| msg_info "Updating Chrony" | ||
| upgrade_packages_with_retry chrony | ||
| systemctl restart chrony | ||
| msg_ok "Updated Chrony" | ||
|
|
||
| if [[ -f /etc/default/gpsd ]]; then | ||
| msg_info "Updating gpsd" | ||
| upgrade_packages_with_retry gpsd gpsd-clients | ||
| systemctl restart gpsd | ||
| msg_ok "Updated gpsd" | ||
| fi | ||
| msg_ok "Updated successfully!" | ||
| exit | ||
| } | ||
|
|
||
| start | ||
| build_container | ||
| description | ||
|
|
||
| msg_ok "Completed Successfully!\n" | ||
| echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" | ||
| echo -e "${INFO}${YW}Point your NTP clients at UDP port 123 and check the sources with 'chronyc sources':${CL}" | ||
| echo -e "${GATEWAY}${BGN}${IP}:123${CL}" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Copyright (c) 2021-2026 community-scripts ORG | ||
| # Author: Jan Wiebe Klijnsma (jwklijnsma) | ||
| # License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE | ||
| # Source: https://chrony-project.org/ | ||
|
|
||
| source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" | ||
| color | ||
| verb_ip6 | ||
| catch_errors | ||
| setting_up_container | ||
| network_check | ||
| update_os | ||
|
|
||
| var_ntp_stratum="${var_ntp_stratum:-2}" | ||
|
|
||
| msg_info "Installing Chrony" | ||
| $STD apt install -y chrony | ||
| mkdir -p /etc/systemd/system/chrony.service.d | ||
| cat <<EOF >/etc/systemd/system/chrony.service.d/container.conf | ||
| [Unit] | ||
| ConditionCapability= | ||
| ConditionVirtualization= | ||
| EOF | ||
| cat <<EOF >/etc/default/chrony | ||
| DAEMON_OPTS="-F 1 -x" | ||
| EOF | ||
| systemctl daemon-reload | ||
| msg_ok "Installed Chrony" | ||
|
|
||
| if [[ "$var_ntp_stratum" == "1" ]]; then | ||
| if [[ -z "${var_gps_device:-}" ]]; then | ||
| read -rp "${TAB3}GPS receiver device [/dev/ttyACM0]: " var_gps_device | ||
| fi | ||
| var_gps_device="${var_gps_device:-/dev/ttyACM0}" | ||
| if [[ ! -e "$var_gps_device" ]]; then | ||
| msg_warn "${var_gps_device} is not present yet; Chrony serves as stratum 2 from the pool, and gpsd starts once the receiver is attached and the container restarted" | ||
| fi | ||
|
|
||
| msg_info "Installing gpsd" | ||
| $STD apt install -y gpsd gpsd-clients | ||
| msg_ok "Installed gpsd" | ||
|
|
||
| msg_info "Configuring Chrony as stratum 1" | ||
| cat <<EOF >/etc/chrony/conf.d/server.conf | ||
| refclock SHM 0 refid NMEA offset 0.1 delay 0.2 poll 3 precision 1e-1 | ||
| refclock SOCK /run/chrony.${var_gps_device##*/}.sock refid PPS precision 1e-7 prefer | ||
| allow | ||
| EOF | ||
| systemctl restart chrony | ||
| cat <<EOF >/etc/default/gpsd | ||
| DEVICES="${var_gps_device}" | ||
| GPSD_OPTIONS="-n" | ||
| USBAUTO="false" | ||
| EOF | ||
| mkdir -p /etc/systemd/system/gpsd.service.d | ||
| cat <<EOF >/etc/systemd/system/gpsd.service.d/device.conf | ||
| [Unit] | ||
| ConditionPathExists=${var_gps_device} | ||
| EOF | ||
| systemctl daemon-reload | ||
| systemctl enable -q gpsd | ||
| systemctl restart gpsd | ||
| msg_ok "Configured Chrony as stratum 1" | ||
| else | ||
| if [[ -z "${var_ntp_servers:-}" ]]; then | ||
| read -rp "${TAB3}Upstream NTP servers, space separated [defaults]: " var_ntp_servers | ||
| fi | ||
| if [[ "$var_ntp_stratum" == "2" ]]; then | ||
| var_ntp_servers="${var_ntp_servers:-ntp.time.nl ptbtime1.ptb.de ptbtime2.ptb.de time.nist.gov}" | ||
| else | ||
| var_ntp_servers="${var_ntp_servers:-0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org}" | ||
| fi | ||
|
|
||
| msg_info "Configuring Chrony as stratum ${var_ntp_stratum}" | ||
| sed -i 's/^pool /#pool /' /etc/chrony/chrony.conf | ||
| cat <<EOF >/etc/chrony/conf.d/server.conf | ||
| $(printf "server %s iburst minstratum $((var_ntp_stratum - 1))\n" $var_ntp_servers) | ||
| allow | ||
| EOF | ||
| systemctl restart chrony | ||
| msg_ok "Configured Chrony as stratum ${var_ntp_stratum}" | ||
| fi | ||
|
|
||
| motd_ssh | ||
| customize | ||
| cleanup_lxc |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| "name": "Chrony", | ||
| "slug": "chrony", | ||
| "categories": [ | ||
| 4 | ||
| ], | ||
| "date_created": "2026-11-18", | ||
| "type": "ct", | ||
| "updateable": true, | ||
| "privileged": false, | ||
| "interface_port": null, | ||
| "documentation": "https://chrony-project.org/documentation.html", | ||
| "website": "https://chrony-project.org/", | ||
| "repository": "https://gitlab.com/chrony/chrony", | ||
| "architectures": [ | ||
| "amd64", | ||
| "arm64" | ||
| ], | ||
| "platforms": [ | ||
| "pve", | ||
| "incus" | ||
| ], | ||
| "logo": null, | ||
| "description": "Chrony is an NTP implementation that runs here as a time server for your network, at stratum 1, 2 or 3. Stratum 1 uses a GPS receiver through gpsd as its reference clock (NMEA and, where available, PPS); stratum 2 syncs from public stratum 1 servers and stratum 3 from the NTP pool or your own stratum 2 server.", | ||
| "install_methods": [ | ||
| { | ||
| "type": "default", | ||
| "script": "ct/chrony.sh", | ||
| "config_path": "/etc/chrony/conf.d/server.conf", | ||
| "resources": { | ||
| "cpu": 1, | ||
| "ram": 512, | ||
| "hdd": 4, | ||
| "os": "Debian", | ||
| "version": "13" | ||
| } | ||
| } | ||
| ], | ||
| "default_credentials": { | ||
| "username": null, | ||
| "password": null | ||
| }, | ||
| "app_vars": [ | ||
| { | ||
| "name": "var_ntp_stratum", | ||
| "label": "NTP Stratum", | ||
| "type": "select", | ||
| "options": [ | ||
| "2", | ||
| "3", | ||
| "1" | ||
| ], | ||
| "default": "2" | ||
| }, | ||
| { | ||
| "name": "var_gps_device", | ||
| "label": "GPS Receiver Device (stratum 1)", | ||
| "type": "text", | ||
| "default": "/dev/ttyACM0" | ||
| }, | ||
| { | ||
| "name": "var_ntp_servers", | ||
| "label": "Upstream NTP Servers (stratum 2/3, space separated)", | ||
| "type": "text" | ||
| } | ||
| ], | ||
| "notes": [ | ||
| { | ||
| "text": "Stratum 1 needs a USB GPS receiver on the Proxmox host before the container is created; it runs privileged so /dev/ttyACM0-1 and /dev/ttyUSB0-1 are passed through. Stratum 2 and 3 run unprivileged.", | ||
| "type": "info" | ||
| }, | ||
| { | ||
| "text": "Stratum 1 needs a GPS fix: wait until 'chronyc sources' marks NMEA or PPS with '*', and tune the NMEA offset in /etc/chrony/conf.d/server.conf if it is rejected.", | ||
| "type": "warning" | ||
| }, | ||
| { | ||
| "text": "Stratum 2 syncs from TimeNL, PTB and NIST, stratum 3 from pool.ntp.org; set var_ntp_servers to use your own upstream servers.", | ||
| "type": "info" | ||
| } | ||
| ] | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.