-
Notifications
You must be signed in to change notification settings - Fork 22
RDKEMW-14726 : Implement Chrony runtime selection for Time Sync #632
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
Changes from 23 commits
209fed7
ff4de02
a3806be
7e21c81
7c9f478
0fc33a7
2064cfc
06f80bc
f3d603f
e8d62b1
fb1e339
2d281a5
a6d51c0
a6af6f8
6f9cbca
c089159
c187fdb
743079c
020dcd9
fd5e8e4
75a616f
bbe4013
8222256
3ad063f
6f3b605
9f96459
c98feab
25e07f6
5c73a64
762de71
d5e81b1
93b0328
e79cfaa
3edd7d9
7ddf68b
3ba0ed7
5ce5546
b0a07f0
6dff2da
9e1f056
3661cc1
42ca1ce
82d0261
aea254f
a7474d8
186428f
8473ca9
8f21c96
00b9681
5ede993
2b738ab
430e31d
61a0d58
f4d8dc5
1902e5a
4708928
590a088
3d643ab
563cb92
af50cbb
a8d26f0
7c8d5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| FILESEXTRAPATHS:prepend := "${THISDIR}/files:" | ||
|
|
||
|
|
||
| SRC_URI += "file://chrony.conf \ | ||
| file://chronyd.service \ | ||
| file://rdk_chrony.conf \ | ||
| file://chrony-sync-notify.sh \ | ||
| file://chrony-sync-notify.service \ | ||
| file://chrony-conf-update.sh \ | ||
| file://chrony-tracking.timer \ | ||
| file://chrony-tracking.service \ | ||
| file://chrony_tracking.sh \ | ||
| " | ||
|
|
||
| do_install:append() { | ||
| # Binaries | ||
| install -m 0755 ${S}/chronyc ${D}${sbindir} | ||
| install -d ${D}${base_libdir}/rdk | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| #config File | ||
| rm -rf ${D}${sysconfdir}/chrony.conf | ||
| install -m 0644 ${WORKDIR}/chrony.conf ${D}${sysconfdir}/ | ||
| install -m 0644 ${WORKDIR}/rdk_chrony.conf ${D}${sysconfdir}/ | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| install -m 0755 ${WORKDIR}/chrony-sync-notify.sh ${D}${base_libdir}/rdk | ||
| install -m 0755 ${WORKDIR}/chrony-conf-update.sh ${D}${base_libdir}/rdk | ||
| install -m 0755 ${WORKDIR}/chrony_tracking.sh ${D}${base_libdir}/rdk | ||
|
|
||
|
|
||
| # service to start chrony | ||
| rm -rf ${D}${systemd_unitdir}/system/chronyd.service | ||
| install -m 0644 ${WORKDIR}/chronyd.service ${D}${systemd_unitdir}/system/ | ||
| install -m 0644 ${WORKDIR}/chrony-sync-notify.service ${D}${systemd_unitdir}/system/ | ||
| install -m 0644 ${WORKDIR}/chrony-tracking.service ${D}${systemd_unitdir}/system/ | ||
| install -m 0644 ${WORKDIR}/chrony-tracking.timer ${D}${systemd_unitdir}/system/ | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| FILES:${PN} += "${sbindir}/chronyc" | ||
| FILES:${PN} += "${base_libdir}/rdk/chrony-sync-notify.sh" | ||
| CONFFILES:${PN} += "${sysconfdir}/chrony.conf" | ||
| CONFFILES:${PN} += "${sysconfdir}/rdk_chrony.conf" | ||
| FILES:${PN} += "${base_libdir}/rdk/chrony-conf-update.sh" | ||
| FILES:${PN} += "${base_libdir}/rdk/chrony_tracking.sh" | ||
|
|
||
| SYSTEMD_SERVICE:${PN} += "chronyd.service" | ||
| SYSTEMD_SERVICE:${PN} += "chrony-sync-notify.service" | ||
| SYSTEMD_SERVICE:${PN} += "chrony-tracking.service" | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
| SYSTEMD_SERVICE:${PN} += "chrony-tracking.timer" | ||
|
|
||
|
|
||
| inherit syslog-ng-config-gen | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| SYSLOG-NG_FILTER = "chronyd" | ||
| SYSLOG-NG_SERVICE_chronyd = "chronyd.service" | ||
| SYSLOG-NG_DESTINATION_chronyd = "chrony.log" | ||
| SYSLOG-NG_LOGRATE_chronyd = "low" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| #!/bin/bash | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| ############################################################################## | ||
| # If not stated otherwise in this file or this component's LICENSE file the | ||
|
Check failure on line 3 in recipes-support/chrony/files/chrony-conf-update.sh
|
||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| # following copyright and licenses apply: | ||
| # | ||
| # Copyright 2020 RDK Management | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
Check failure on line 8 in recipes-support/chrony/files/chrony-conf-update.sh
|
||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| ############################################################################## | ||
| # Purpose : To generate the chrony configuration file (/etc/rdk_chrony.conf) | ||
| # Scope : RDK Devices | ||
| # Usage : Invoke by systemd service as part of chrony integration | ||
|
|
||
|
|
||
| LOG_FILE="/opt/logs/chrony.log" | ||
| attempts=1 | ||
| max_attempts=5 | ||
| CHRONY_CONF=/etc/rdk_chrony.conf | ||
|
|
||
| if [ -f /etc/env_setup.sh ]; then | ||
| . /etc/env_setup.sh | ||
| fi | ||
|
|
||
| #create directory if not already available | ||
| /bin/mkdir -p /var/lib/chrony | ||
|
|
||
| #Log framework to print timestamp and source script name | ||
| ntpLog() | ||
| { | ||
| echo "`/bin/timestamp` : $0: $*" >> $LOG_FILE | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
| } | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| # NTP URL from the property file | ||
| get_ntp_hosts() { | ||
| if [ -f /lib/rdk/getPartnerProperty.sh ]; then | ||
| hostName=`/lib/rdk/getPartnerProperty.sh ntpHost` | ||
| hostName2=`/lib/rdk/getPartnerProperty.sh ntpHost2` | ||
| hostName3=`/lib/rdk/getPartnerProperty.sh ntpHost3` | ||
| hostName4=`/lib/rdk/getPartnerProperty.sh ntpHost4` | ||
| hostName5=`/lib/rdk/getPartnerProperty.sh ntpHost5` | ||
|
|
||
| minPoll=`/lib/rdk/getPartnerProperty.sh NTPMinpoll` | ||
| maxPoll=`/lib/rdk/getPartnerProperty.sh NTPMaxpoll` | ||
|
|
||
| # Fetch directives for each NTP server (optional, fallback to server) | ||
| directive1=$( /lib/rdk/getPartnerProperty.sh NTPServer1Directive ) | ||
| directive2=$( /lib/rdk/getPartnerProperty.sh NTPServer2Directive ) | ||
| directive3=$( /lib/rdk/getPartnerProperty.sh NTPServer3Directive ) | ||
| directive4=$( /lib/rdk/getPartnerProperty.sh NTPServer4Directive ) | ||
| directive5=$( /lib/rdk/getPartnerProperty.sh NTPServer5Directive ) | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| fi | ||
| } | ||
|
|
||
| get_ntp_hosts_from_bootstrap() { | ||
| BOOTSTRAP="/opt/secure/RFC/bootstrap.ini" | ||
|
|
||
| if [ ! -f "$BOOTSTRAP" ]; then | ||
| ntpLog "bootstrap.ini not found at $BOOTSTRAP" | ||
| return 1 | ||
| fi | ||
|
|
||
| # Helper to fetch key=value from bootstrap.ini (first match) | ||
| get_bs_val() { | ||
| key="$1" | ||
| # Escape regex metacharacters in key so it is matched literally | ||
| escaped_key=$(printf '%s\n' "$key" | sed 's/[][\\.^$*]/\\&/g') | ||
| # Extract RHS after '=' and trim whitespace | ||
| grep -m1 -E "^[[:space:]]*$escaped_key=" "$BOOTSTRAP" 2>/dev/null | \ | ||
| cut -d'=' -f2- | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | ||
| } | ||
|
|
||
| bs1="$(get_bs_val 'Device.Time.NTPServer1')" | ||
| bs2="$(get_bs_val 'Device.Time.NTPServer2')" | ||
| bs3="$(get_bs_val 'Device.Time.NTPServer3')" | ||
| bs4="$(get_bs_val 'Device.Time.NTPServer4')" | ||
| bs5="$(get_bs_val 'Device.Time.NTPServer5')" | ||
|
|
||
| # Only fill missing values (don’t override TR-181 values if present) | ||
| [ -z "$hostName" ] && hostName="$bs1" | ||
| [ -z "$hostName2" ] && hostName2="$bs2" | ||
| [ -z "$hostName3" ] && hostName3="$bs3" | ||
| [ -z "$hostName4" ] && hostName4="$bs4" | ||
| [ -z "$hostName5" ] && hostName5="$bs5" | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
|
|
||
| ntpLog "Retrieve NTP Server URL from /lib/rdk/getPartnerProperty.sh..." | ||
| while [ "$attempts" -le "$max_attempts" ]; do | ||
|
|
||
| ntpLog "Attempt $attempts/$max_attempts to retrieve NTP server URL(s)..." | ||
| get_ntp_hosts | ||
|
|
||
| if [ "$hostName" ] || [ "$hostName2" ] || [ "$hostName3" ] || [ "$hostName4" ] || [ "$hostName5" ]; then | ||
| break | ||
| fi | ||
|
|
||
| # If this is the last attempt, try bootstrap as fallback and then break | ||
| if [ $attempts -eq $max_attempts ]; then | ||
| ntpLog "TR-181 returned empty NTP server list; falling back to /opt/secure/RFC/bootstrap.ini..." | ||
| get_ntp_hosts_from_bootstrap | ||
| break | ||
| fi | ||
|
|
||
| sleep 3 | ||
| attempts=$((attempts + 1)) | ||
|
|
||
| done | ||
|
|
||
| # Use defaults if not set | ||
| [ -z "$minPoll" ] && minPoll="10" | ||
| [ -z "$maxPoll" ] && maxPoll="12" | ||
| ntpLog "Minpoll:$minPoll MaxPoll:$maxPoll" | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
|
|
||
| hosts=("$hostName" "$hostName2" "$hostName3" "$hostName4" "$hostName5") | ||
| directives=("$directive1" "$directive2" "$directive3" "$directive4" "$directive5") | ||
| ntpLog "NTP Server URL for the partner:$hosts" | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
|
|
||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| conf_written=0 | ||
| > "$CHRONY_CONF" | ||
| for i in $(seq 0 4); do | ||
| host="${hosts[$i]}" | ||
| directive="${directives[$i]}" | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| if [ -n "$host" ]; then | ||
| # use directive if set, else default to server | ||
| [ -z "$directive" ] && directive="server" | ||
| printf "%s %s iburst minpoll %s maxpoll %s\n" "$directive" "$host" "$minPoll" "$maxPoll" >> "$CHRONY_CONF" | ||
| conf_written=1 | ||
| fi | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
| done | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| # fallback if no valid host found | ||
| if [ "$conf_written" -eq 0 ]; then | ||
| printf "server time.google.com iburst minpoll %s maxpoll %s\n" "$minPoll" "$maxPoll" >> "$CHRONY_CONF" | ||
| ntpLog "No valid NTP servers found, using fallback: time.google.com" | ||
| fi | ||
|
|
||
| ntpLog "Successfully updated $CHRONY_CONF" | ||
| exit 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [Unit] | ||
| Description=Notify when Chrony time sync is completed | ||
| Documentation=man:chronyc(1) | ||
| After=chronyd.service | ||
| ConditionPathExists=/opt/secure/RFC/chrony/chronyd_enabled | ||
|
|
||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/lib/rdk/chrony-sync-notify.sh | ||
|
|
||
| [Install] | ||
| WantedBy=chronyd.service | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/bin/sh | ||
|
tdeva14 marked this conversation as resolved.
|
||
|
|
||
| LOG_FILE=/opt/logs/chrony.log | ||
| NTP_DIR="/tmp/systimemgr" | ||
| NTP_FILE="$NTP_DIR/ntp" | ||
| CLOCK_EVENT="/tmp/clock-event" | ||
| SYSTEMD_DIR="/var/lib/systemd/" | ||
| SYSTEMD_CLOCK="$SYSTEMD_DIR/clock" | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
|
|
||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
sindhu-krishnan marked this conversation as resolved.
|
||
| log() { | ||
| echo "$1" >> "$LOG_FILE" | ||
| } | ||
|
|
||
| is_synced() { | ||
| chronyc tracking 2>/dev/null | grep -q "Leap status *: Normal" | ||
| } | ||
|
|
||
|
|
||
| # Wait for sync only if not already synced | ||
| #This command will wait up to about 5 minutes (3000 tries * 0.1 seconds each) until chrony reports that the system clock is synchronized | ||
| if is_synced; then | ||
| log "Chrony already synchronised" | ||
| exit 0 #TBD - Don't log milestones whenever chronyd started | ||
| else | ||
| log "Waiting for Chrony synchronisation..." | ||
| chronyc waitsync 3000 0 0 0.1 || { | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
| log "waitsync failed or timed out after 5 minutes" | ||
| exit 1 | ||
| } | ||
| fi | ||
|
|
||
| if [ ! -f "$CLOCK_EVENT" ]; then | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| touch "$CLOCK_EVENT" && log "Created $CLOCK_EVENT" | ||
| fi | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| # Create required directory | ||
| if [ ! -d "$NTP_DIR" ]; then | ||
| log "Creating $NTP_DIR" | ||
| mkdir -p "$NTP_DIR" | ||
| fi | ||
|
|
||
| # Create flag files | ||
| if [ ! -f "$NTP_FILE" ]; then | ||
| touch "$NTP_FILE" && log "Created $NTP_FILE" | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| fi | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| if [ ! -d "$SYSTEMD_DIR" ]; then | ||
| log "Creating $SYSTEMD_DIR" | ||
| mkdir -p "$SYSTEMD_DIR" | ||
| fi | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| if [ ! -f "$SYSTEMD_CLOCK" ]; then | ||
| touch "$SYSTEMD_CLOCK" && log "Created $SYSTEMD_CLOCK" | ||
|
tdeva14 marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| echo "Synchronized" > /tmp/ntp_status | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| exit 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Unit] | ||
| Description=Chrony telemetry data collection service | ||
| ConditionPathExists=/opt/secure/RFC/chrony/chronyd_enabled | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/lib/rdk/chrony_tracking.sh | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Unit] | ||
| Description=Run chrony telemetry collection every 15 minutes | ||
|
|
||
| [Timer] | ||
| OnBootSec=120s | ||
| OnUnitActiveSec=15min | ||
| Unit=chrony-tracking.service | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #Configuration values in this file are defaults and typically do not change. | ||
| #Server configurations are added at runtime as it may change based on the partner. | ||
|
|
||
| # The next option causes a message to be written to syslog when chronyd | ||
| # has to correct an error above 0.5 seconds (you can use any amount you | ||
| # like). | ||
| logchange 0.5 | ||
|
|
||
| # Logging | ||
| logdir /opt/logs/chrony | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
| log measurements statistics tracking | ||
|
sindhu-krishnan marked this conversation as resolved.
Outdated
|
||
|
|
||
|
||
| # Step the system clock instead of slewing it if the adjustment is larger than | ||
| # one second, but only in the first three clock updates. | ||
| makestep 1.0 3 | ||
|
|
||
|
|
||
| # Record the rate at which the system clock gains/losses time. | ||
| driftfile /var/lib/chrony/drift | ||
|
|
||
| # This directive can be used | ||
| # to enable a mode in which the RTC is periodically set to the system | ||
| # time, with no tracking of its drift. | ||
| rtcsync | ||
|
|
||
| # Stop bad estimates upsetting machine clock. | ||
| maxupdateskew 100.0 | ||
|
tdeva14 marked this conversation as resolved.
|
||
|
|
||
| include /etc/rdk_chrony.conf | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/sh | ||
| LOGFILE="/opt/logs/chrony.log" | ||
|
|
||
| timestamp=$(date "+%Y-%m-%d %H:%M:%S") | ||
|
|
||
| { | ||
| echo "$timestamp chrony telemetry:" | ||
| chronyc tracking | ||
| echo "" | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| } >> "$LOGFILE" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [Unit] | ||
| Description=NTP client/server | ||
| Documentation=man:chronyd(8) man:chrony.conf(5) | ||
| Wants=nvram.service tr69hostif.service network-up.target | ||
| After=nvram.service tr69hostif.service network-up.target | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| ConditionPathExists=/opt/secure/RFC/chrony/chronyd_enabled | ||
| #Conflicts=systemd-timesyncd.service | ||
| ConditionCapability=CAP_SYS_TIME | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| [Service] | ||
| Type=forking | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| PIDFile=/run/chrony/chronyd.pid | ||
| ExecStartPre=/lib/rdk/chrony-conf-update.sh | ||
| ExecStart=/usr/sbin/chronyd | ||
|
sindhu-krishnan marked this conversation as resolved.
|
||
| ExecStartPost=/lib/rdk/logMilestone.sh "NTP_CLIENT_STARTED" | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
|
|
||
| [Install] | ||
| WantedBy=network-up.target | ||
|
sindhu-krishnan marked this conversation as resolved.
sindhu-krishnan marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Configuration values in this file may change dynamically via TR-181 parameters. | ||
| #server time.google.com iburst minpoll 10 maxpoll 12 | ||
| #server time.xfinity.com iburst minpoll 10 maxpoll 12 | ||
|
tdeva14 marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.