Skip to content

Commit

Permalink
Ensure NTP is configured after IP
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Nov 21, 2017
1 parent 8401e04 commit 3989539
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.7.0 (2017-11-21)

* [bugfix] Ensure NTP is configured after the interface is configured
* Increase NTP server timeout to 60 seconds (20 seconds per attempt)
* Send NTP setup queries to log file
* Add module.l with module info

## 1.6.0 (2017-10-14)

* Restore "sleep" (10s) while waiting for network interface
Expand Down
8 changes: 8 additions & 0 deletions module.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[de MODULE_INFO
("name" "tinycore-network")
("version" "1.7.0")
("summary" "TinyCore static/dhcp networking")
("source" "https://a1w.ca")
("author" "Alexander Williams")
("license" "MIT")
("copyright" "(c) 2015-2017 Alexander Williams, Unscramble <[email protected]>") ]
28 changes: 16 additions & 12 deletions network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
#
# MIT License
# Copyright (c) 2015-2017 Alexander Williams, Unscramble <[email protected]>
#
# VERSION: 1.7.0

. /etc/init.d/tc-functions
set -a

config="/usr/local/etc/network.conf"
ntp_tries=0
ntptimeout=30 # seconds
ntptimeout=60 # seconds
ntpretry=20 # seconds
interface_tries=0

/sbin/udevadm settle --timeout=5

set_ntpdate() {
if [ ${ntpserver-} ]; then
ntp_tries=$(( $ntp_tries + 10 ))
ntp_tries=$(( $ntp_tries + $ntpretry ))
if [ "$ntp_tries" -le "$ntptimeout" ]; then
/usr/bin/timeout -t 10 /usr/sbin/ntpd -d -n -q -p "$ntpserver" >/dev/null 2>&1 || set_ntpdate
/usr/bin/timeout -t $ntpretry /usr/sbin/ntpd -d -n -q -p "$ntpserver" >>/var/log/ntp.log 2>&1 || set_ntpdate
fi
fi
}
Expand Down Expand Up @@ -50,15 +53,6 @@ if [ -f "$config" ]; then
check_interface
echo "${GREEN} Done.${NORMAL}"

if [ "$ntpserver" ]; then
echo -n "${GREEN}Waiting ${MAGENTA}${ntptimeout}s${GREEN} for NTP from ${MAGENTA}$ntpserver${NORMAL}"
echo "$ntpserver" > /etc/sysconfig/ntpserver
set_ntpdate
echo "${GREEN} Done.${NORMAL}"
else
> /etc/sysconfig/ntpserver
fi

case "$mode" in
static)
/opt/network_static.sh
Expand All @@ -67,6 +61,16 @@ if [ -f "$config" ]; then
/opt/network_dhcp.sh
;;
esac

# configure NTP after the interface is configured
if [ "$ntpserver" ]; then
echo -n "${GREEN}Waiting up to ${MAGENTA}${ntptimeout}s${GREEN} for NTP from ${MAGENTA}$ntpserver${NORMAL}"
echo "$ntpserver" > /etc/sysconfig/ntpserver
set_ntpdate
echo "${GREEN} Done.${NORMAL}"
else
> /etc/sysconfig/ntpserver
fi
else
echo "${RED}Missing network config: ${RED}${config}${NORMAL}"
exit 1
Expand Down

0 comments on commit 3989539

Please sign in to comment.