Skip to contentSkip to conversation

dhcp: add dhclient.service

PATCH New Chen Qi 1 participant 2 messages Dec 17, 2014

lore
Share & tools
lore

Chen Qi

author
#0 lore raw

v2 cover dhcp: add dhclient.service

The following changes since commit 68ddb28a68ceb59cd1ed322c16143827ce1ac712:

distrodata_class: checkpkg make usage of latest_versionstring methods in bitbake fetcher (2014-11-28 13:59:52 +0000)

are available in the git repository at:

git://git.pokylinux.org/poky-contrib ChenQi/systemd-dhclient
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/systemd-dhclient

Chen Qi (1):
dhcp: add dhclient.service

 meta/recipes-connectivity/dhcp/dhcp.inc            | 16 ++++++---
 .../dhcp/files/dhclient-systemd-wrapper            | 39 ++++++++++++++++++++++
 .../dhcp/files/dhclient.service                    | 13 ++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100644 meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper
 create mode 100644 meta/recipes-connectivity/dhcp/files/dhclient.service
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 1/1 dhcp: add dhclient.service

Add dhclient.service. This service file mainly comes from meta-systemd, with modifications to take nfs boot into consideration.

While using eth0 as the nfsboot interface, we'd like dhclient service to skip it like what ifup and connman do in sysvinit.

---
 meta/recipes-connectivity/dhcp/dhcp.inc            | 16 ++++++---
 .../dhcp/files/dhclient-systemd-wrapper            | 39 ++++++++++++++++++++++
 .../dhcp/files/dhclient.service                    | 13 ++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100644 meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper
 create mode 100644 meta/recipes-connectivity/dhcp/files/dhclient.service
meta/recipes-connectivity/dhcp/dhcp.inc +12 -4
index 4949e02..258ef8f 100644
@@ -17,17 +17,21 @@ SRC_URI = "ftp://ftp.isc.org/isc/dhcp/${PV}/dhcp-${PV}.tar.gz \
            file://init-relay file://default-relay \
            file://init-server file://default-server \
            file://dhclient.conf file://dhcpd.conf \
-           file://dhcpd.service file://dhcrelay.service"
+           file://dhcpd.service file://dhcrelay.service file://dhclient.service \
+           file://dhclient-systemd-wrapper"
 
 inherit autotools systemd
 
-SYSTEMD_PACKAGES = "${PN}-server ${PN}-relay"
+SYSTEMD_PACKAGES = "${PN}-server ${PN}-relay ${PN}-client"
 SYSTEMD_SERVICE_${PN}-server = "dhcpd.service"
 SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
 
 SYSTEMD_SERVICE_${PN}-relay = "dhcrelay.service"
 SYSTEMD_AUTO_ENABLE_${PN}-relay = "disable"
 
+SYSTEMD_SERVICE_${PN}-client = "dhclient.service"
+SYSTEMD_AUTO_ENABLE_${PN}-client = "disable"
+
 TARGET_CFLAGS += "-D_GNU_SOURCE"
 EXTRA_OECONF = "--with-srv-lease-file=${localstatedir}/lib/dhcp/dhcpd.leases \
                 --with-srv6-lease-file=${localstatedir}/lib/dhcp/dhcpd6.leases \
@@ -62,10 +66,14 @@ do_install_append () {
 
 	# Install systemd unit files
 	install -d ${D}${systemd_unitdir}/system
+	install -d ${D}${base_sbindir}
+	install -m 0755 ${WORKDIR}/dhclient-systemd-wrapper ${D}${base_sbindir}/dhclient-systemd-wrapper
 	install -m 0644 ${WORKDIR}/dhcpd.service ${D}${systemd_unitdir}/system
 	install -m 0644 ${WORKDIR}/dhcrelay.service ${D}${systemd_unitdir}/system
+	install -m 0644 ${WORKDIR}/dhclient.service ${D}${systemd_unitdir}/system
 	sed -i -e 's,@SBINDIR@,${sbindir},g' ${D}${systemd_unitdir}/system/dhcpd.service ${D}${systemd_unitdir}/system/dhcrelay.service
-	sed -i -e 's,@SYSCONFDIR@,${sysconfdir},g' ${D}${systemd_unitdir}/system/dhcpd.service
+	sed -i -e 's,@SYSCONFDIR@,${sysconfdir},g' ${D}${systemd_unitdir}/system/dhcpd.service ${D}${systemd_unitdir}/system/dhclient.service
+	sed -i -e 's,@BASE_SBINDIR@,${base_sbindir},g' ${D}${systemd_unitdir}/system/dhclient.service
 }
 
 PACKAGES += "dhcp-server dhcp-server-config dhcp-client dhcp-relay dhcp-omshell"
@@ -81,7 +89,7 @@ FILES_dhcp-server-config = "${sysconfdir}/default/dhcp-server ${sysconfdir}/dhcp
 
 FILES_dhcp-relay = "${sbindir}/dhcrelay ${sysconfdir}/init.d/dhcp-relay ${sysconfdir}/default/dhcp-relay"
 
-FILES_dhcp-client = "${base_sbindir}/dhclient ${base_sbindir}/dhclient-script ${sysconfdir}/dhcp/dhclient.conf"
+FILES_dhcp-client = "${base_sbindir}/dhclient ${base_sbindir}/dhclient-script ${sysconfdir}/dhcp/dhclient.conf ${base_sbindir}/dhclient-systemd-wrapper"
 RDEPENDS_dhcp-client = "bash"
 
 FILES_dhcp-omshell = "${bindir}/omshell"
meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper new file +39 -0
new file mode 100644
index 0000000..08afd30
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# In case the interface is used for nfs, skip it.
+nfsroot=0
+interfaces=""
+exec 9<&0 < /proc/mounts
+while read dev mtpt fstype rest; do
+    if test $mtpt = "/" ; then
+        case $fstype in
+            nfs | nfs4)
+                nfsroot=1
+                nfs_addr=`echo $rest | sed -e 's/^.*addr=\([0-9.]*\).*$/\1/'`
+                break
+                ;;
+            *)
+                ;;
+        esac
+    fi
+done
+exec 0<&9 9<&-
+
+if [ $nfsroot -eq 0 ]; then
+    interfaces="$INTERFACES"
+else
+    if [ -x /bin/ip -o -x /sbin/ip ] ; then
+	nfs_iface=`ip route get $nfs_addr | grep dev | sed -e 's/^.*dev \([-a-z0-9.]*\).*$/\1/'`
+    fi
+    for i in $INTERFACES; do
+	if test "x$i" = "x$nfs_iface"; then
+            echo "dhclient skipping nfsroot interface $i"
+	else
+	    interfaces="$interfaces $i"
+	fi
+    done
+fi
+
+if test "x$interfaces" != "x"; then
+    /sbin/dhclient -cf /etc/dhcp/dhclient.conf -q -lf /var/lib/dhcp/dhclient.leases $interfaces
+fi
meta/recipes-connectivity/dhcp/files/dhclient.service new file +13 -0
new file mode 100644
index 0000000..9ddb4d1
@@ -0,0 +1,13 @@
+[Unit]
+Description=Dynamic Host Configuration Protocol (DHCP)
+Wants=network.target
+Before=network.target
+After=systemd-udevd.service
+
+[Service]
+EnvironmentFile=-@SYSCONFDIR@/default/dhcp-client
+ExecStart=@BASE_SBINDIR@/dhclient-systemd-wrapper
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
Signature · 1 line
1.9.1