Package: ntp
Version: 1:4.2.8p10+dfsg-5
Severity: wishlist

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Dear Maintainer,

If a system uses systemd-networkd to configure networking, but wants
to use ntp to sync time, ntp & networkd should integrate with each
other to reconfigure ntp with timeservers that are discovered by
networkd (either configs or DHCP).

To achieve this I'm proposing to add .path systemd unit that monitors
and triggers dhcp-enter-hook to be rerun whenever systemd-networkd
state changes and create an updated dhcp.conf in the /run.

Regards,

Dimitri.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJZ+zYvAAoJEMrC2LnNLKX5KJMH/0syc1CSKpxobGINMVay0LCx
TUX04ffIZdDNaqro9Uh9mkOJmgkCYf5yyMF7sKZmgeA2U7ETetkNxKREkcuqWX40
TC9wlRucT20vDUHUUR2H69DLGOBVqY3W7NUeuXS6jqV6rqJhHJ/xJ+DHUSKEm666
rGIRZ2uXlbUlED5DlQSAIAZ9mSCu0pp1KFaisp3fjkGsjhmf1rBDs2IMuXHVNSay
6Ax4Z5gX+7M6GQJ4iYT76vopfMqzjFz2QhdaIHNkJ/BzAynClspWLAYmi1YZuj1o
mfTqFcGt5ixr+hOhzdWc43lF3vLu9WnqR8gMvXx7DGj9tiFYJw7V2a71YqG17C8=
=DyPZ
-----END PGP SIGNATURE-----
>From a6cc212aef19fe86a77a88c76ace6677be91f6e1 Mon Sep 17 00:00:00 2001
From: Dimitri John Ledkov <x...@ubuntu.com>
Date: Tue, 3 Oct 2017 13:23:33 +0100
Subject: [PATCH] debian/ntp.dhcp,ntp-systemd-netif.service|.path: integrate
 picking up networkd discovered NTP servers.

networkd has it's own implementation of DHCP client which does not by
default execute isc-dhcp client hooks. However the networkd DHCP
leases are serialised in a runtime directory and it is supported to
establish inotify watches on them. The combined state file is also
written out by networkd which lists acquired/configured NTP
servers. Implement strategy similar to systemd-timesyncd and parse the
networkd state file.  Also add a .path unit to trigger dhcp hook,
whenever networkd state is updated. This integration enables one to
use ntp for timesyncing on systems that use networkd for networking
configuration, instead of ifupdown + isc-dhclient.
---
 debian/changelog                 |  7 +++++++
 debian/ntp-systemd-netif.path    | 10 ++++++++++
 debian/ntp-systemd-netif.service |  4 ++++
 debian/ntp.dhcp                  | 10 ++++++----
 debian/rules                     |  3 +++
 5 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 debian/ntp-systemd-netif.path
 create mode 100644 debian/ntp-systemd-netif.service

diff --git a/debian/changelog b/debian/changelog
index cb4d4e2..90d9cf0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+ntp (1:4.2.8p10+dfsg-6) UNRELEASED; urgency=medium
+
+  * debian/ntp.dhcp,ntp-systemd-netif.service|.path: integrate picking up
+    networkd discovered NTP servers.
+
+ -- Dimitri John Ledkov <x...@ubuntu.com>  Tue, 03 Oct 2017 13:16:10 +0100
+
 ntp (1:4.2.8p10+dfsg-5) unstable; urgency=medium
 
   * Fix arch:all FTBFS due to improper moving of sntp manpage (Closes: #865227)
diff --git a/debian/ntp-systemd-netif.path b/debian/ntp-systemd-netif.path
new file mode 100644
index 0000000..a5c44c6
--- /dev/null
+++ b/debian/ntp-systemd-netif.path
@@ -0,0 +1,10 @@
+[Unit]
+DefaultDependencies=no
+After=systemd-networkd.service
+
+[Path]
+PathExists=/run/systemd/netif/state
+PathChanged=/run/systemd/netif/state
+
+[Install]
+WantedBy=systemd-networkd.target
diff --git a/debian/ntp-systemd-netif.service b/debian/ntp-systemd-netif.service
new file mode 100644
index 0000000..27610f9
--- /dev/null
+++ b/debian/ntp-systemd-netif.service
@@ -0,0 +1,4 @@
+[Service]
+Environment=reason=BOUND
+ExecStart=/bin/sh -c '. /etc/dhcp/dhclient-exit-hooks.d/ntp'
+
diff --git a/debian/ntp.dhcp b/debian/ntp.dhcp
index eedf6d9..60aebe0 100644
--- a/debian/ntp.dhcp
+++ b/debian/ntp.dhcp
@@ -17,12 +17,14 @@ ntp_servers_setup_remove() {
 
 
 ntp_servers_setup_add() {
-	if [ -e $NTP_DHCP_CONF ] && [ "$new_ntp_servers" = "$old_ntp_servers" ]; then
+	networkd_ntp=$(sed -n 's/NTP=//p' /run/systemd/netif/state 2>/dev/null)
+
+	if [ -z "$new_ntp_servers" ] && [ -z "$networkd_ntp" ]; then
+		ntp_servers_setup_remove
 		return
 	fi
 
-	if [ -z "$new_ntp_servers" ]; then
-		ntp_servers_setup_remove
+	if [ -e $NTP_DHCP_CONF ] && [ "$new_ntp_servers" = "$old_ntp_servers" ] && [ -z "$networkd_ntp" ] ; then
 		return
 	fi
 
@@ -36,7 +38,7 @@ ntp_servers_setup_add() {
 	  echo "# here will be lost at the next DHCP event.  Edit $NTP_CONF instead."
 	  echo
 	  echo "# NTP server entries received from DHCP server"
-	  for server in $new_ntp_servers; do
+	  for server in $new_ntp_servers $networkd_ntp; do
 		echo "server $server iburst"
 	  done
 	  echo
diff --git a/debian/rules b/debian/rules
index 8eb7dd9..42f189e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -36,6 +36,8 @@ override_dh_install:
 	install -D -m 0755 debian/ntp.networkmanager debian/ntp/etc/NetworkManager/dispatcher.d/ntp
 	install -D -m 0644 debian/ntpdate.dhcp debian/ntpdate/etc/dhcp/dhclient-exit-hooks.d/ntpdate
 	install -D -m 0755 debian/ntpdate-debian debian/ntpdate/usr/sbin/ntpdate-debian
+	install -D -m 0644 debian/ntp-systemd-netif.path debian/ntp/lib/systemd/system/ntp-systemd-netif.path
+	install -D -m 0644 debian/ntp-systemd-netif.service debian/ntp/lib/systemd/system/ntp-systemd-netif.service
 
 	install -D -m 0644 debian/ntp.conf debian/ntp/etc/ntp.conf
 
@@ -56,6 +58,7 @@ override_dh_install:
 	rm -f debian/ntp-doc/usr/share/doc/ntp-doc/html/hints/solaris*
 
 override_dh_installinit:
+	dh_systemd_start -pntp ntp-systemd-netif.path
 	dh_installinit -pntp --error-handler=installinit_error --no-restart-after-upgrade
 	dh_installinit -pntpdate --no-restart-after-upgrade
 	dh_apparmor --profile-name=usr.sbin.ntpd -pntp
-- 
2.7.4

Reply via email to