diff --git a/ct/chrony.sh b/ct/chrony.sh new file mode 100644 index 0000000000..9c9757e9b1 --- /dev/null +++ b/ct/chrony.sh @@ -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}" diff --git a/install/chrony-install.sh b/install/chrony-install.sh new file mode 100644 index 0000000000..462360de9c --- /dev/null +++ b/install/chrony-install.sh @@ -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 </etc/systemd/system/chrony.service.d/container.conf +[Unit] +ConditionCapability= +ConditionVirtualization= +EOF +cat </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 </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 </etc/default/gpsd +DEVICES="${var_gps_device}" +GPSD_OPTIONS="-n" +USBAUTO="false" +EOF + mkdir -p /etc/systemd/system/gpsd.service.d + cat </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 </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 diff --git a/json/chrony.json b/json/chrony.json new file mode 100644 index 0000000000..1fb6bb0a03 --- /dev/null +++ b/json/chrony.json @@ -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" + } + ] +}