Skip to content

Commit

Permalink
Merge pull request motioneye-project#57 from ccrisan/improvement/ntp-…
Browse files Browse the repository at this point in the history
…chrony

Replace ntpd with chrony
  • Loading branch information
ccrisan committed Oct 7, 2020
2 parents 8fc5176 + 9f6a402 commit 0e661a6
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 31 deletions.
1 change: 1 addition & 0 deletions board/common/cleanups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ rm -f ${TARGET}/etc/init.d/S20urandom
rm -f ${TARGET}/etc/init.d/S21rngd
rm -f ${TARGET}/etc/init.d/S48sntp
rm -f ${TARGET}/etc/init.d/S49ntp
rm -f ${TARGET}/etc/init.d/S49chrony
rm -f ${TARGET}/etc/init.d/S50sshd
rm -f ${TARGET}/etc/init.d/S50proftpd
rm -f ${TARGET}/etc/init.d/S50postgresql
Expand Down
28 changes: 11 additions & 17 deletions board/common/overlay/etc/init.d/S50date
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

PROG_DATE="/bin/date"
PROG_NTPD="/usr/sbin/ntpd"
PROG_NTPD="/usr/sbin/chronyd"
PROG_SNTP="/usr/bin/sntp"
LOG_SNTP="/var/log/sntp.log"

Expand Down Expand Up @@ -47,7 +47,11 @@ set_current_date_http() {
}

set_current_date_ntp() {
${PROG_NTPD} -gq &>/dev/null
if [[ -n "${DATE_NTP_SERVER}" ]]; then
sed -i "s/pool .*/pool ${DATE_NTP_SERVER} iburst/" ${NTP_CONF}
fi

${PROG_NTPD} -f ${NTP_CONF} -q -t ${DATE_TIMEOUT} &>/dev/null
if [[ $? == 0 ]]; then
logger -t date "current system date/time set to $(date) via NTP"
return 0
Expand All @@ -58,8 +62,8 @@ set_current_date_ntp() {
}

set_current_date_sntp() {
sntp_args="-t ${DATE_TIMEOUT} -K /var/lib/ntp/kod -Ss"
server=$(cat ${NTP_CONF} | grep server | head -n 1 | cut -d ' ' -f 2)
sntp_args="-t ${DATE_TIMEOUT} -K /dev/null -Ss"
server=$(cat ${NTP_CONF} | grep pool | head -n 1 | cut -d ' ' -f 2)
${PROG_SNTP} ${sntp_args} ${server} &>${LOG_SNTP}
if [[ $? == 0 ]]; then
logger -t date "current system date/time set to $(date) via SNTP"
Expand Down Expand Up @@ -94,32 +98,22 @@ start_http() {
}

start_ntp() {
mkdir -p /var/lib/ntp
touch /var/lib/ntp/kod

cat ${NTP_CONF} | grep -v iburst > ${NTP_CONF}.tmp

if [[ -n "${DATE_NTP_SERVER}" ]]; then
echo "server ${DATE_NTP_SERVER} iburst" > ${NTP_CONF}
else
cat ${SYS_NTP_CONF} | grep iburst > ${NTP_CONF}
sed -i "s/pool .*/pool ${DATE_NTP_SERVER} iburst/" ${NTP_CONF}
fi

cat ${NTP_CONF}.tmp >> ${NTP_CONF}
rm ${NTP_CONF}.tmp

if [[ "${DATE_METHOD}" == "sntp" ]]; then
msg_begin "Setting current date using SNTP"
set_current_date_sntp
test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
else # assuming ntp
msg_begin "Setting current date using NTP"
set_current_date_ntp || set_current_date_ntp
set_current_date_ntp
test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
fi

msg_begin "Starting ntpd"
${PROG_NTPD} -g -c ${NTP_CONF}
${PROG_NTPD} -f ${NTP_CONF}
test $? == 0 && msg_done || msg_fail
}

Expand Down
20 changes: 6 additions & 14 deletions board/common/overlay/etc/ntp.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
tinker panic 0

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst

server 127.127.1.0
fudge 127.127.1.0 stratum 10

restrict default noquery nopeer
restrict 127.0.0.1
restrict ::1

driftfile /var/lib/ntp/ntp.drift
pool pool.ntp.org iburst
driftfile /var/lib/chrony.drift
makestep 1000 10
rtcsync
hwclockfile /data/etc/adjtime
log tracking
2 changes: 2 additions & 0 deletions configs/bananapim1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -69,6 +70,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/nanopineo2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -61,6 +62,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/nanopineo_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -61,6 +62,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/nanopir1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -62,6 +63,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/odroidxu4_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -64,6 +65,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/orangepione_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -64,6 +65,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/orangepizero_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -64,6 +65,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/raspberrypi2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -67,6 +68,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/raspberrypi3_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -67,6 +68,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/raspberrypi4_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -67,6 +68,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/raspberrypi_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -74,6 +75,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 2 additions & 0 deletions configs/tinkerboard_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ BR2_PACKAGE_PCRE=y
BR2_PACKAGE_PCRE_UCP=y
BR2_PACKAGE_SEMVER_SORT=y
BR2_PACKAGE_AUTOSSH=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_CRDA=y
BR2_PACKAGE_DHCP=y
BR2_PACKAGE_DHCP_CLIENT=y
Expand All @@ -65,6 +66,7 @@ BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_SNTP=y
# BR2_PACKAGE_NTP_NTPD is not set
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down

0 comments on commit 0e661a6

Please sign in to comment.