Patchwork [1/1] systemd: add network unit file

login
register
mail settings
Submitter Ivan Sergeev
Date Jan. 28, 2014, 1:54 a.m.
Message ID <1390874097-25597-1-git-send-email-vsergeev@kumunetworks.com>
Download mbox | patch
Permalink /patch/314547/
State New
Headers show

Comments

Ivan Sergeev - Jan. 28, 2014, 1:54 a.m.
Add and enable a systemd unit file to bring up or down network with ifup /
ifdown, analogous to the skeleton/etc/init.d/S40network init script.

Signed-off-by: Ivan Sergeev <vsergeev@kumunetworks.com>
---
 package/systemd/network.service | 21 +++++++++++++++++++++
 package/systemd/systemd.mk      |  9 +++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 package/systemd/network.service

Patch

diff --git a/package/systemd/network.service b/package/systemd/network.service
new file mode 100644
index 0000000..0d77bb8
--- /dev/null
+++ b/package/systemd/network.service
@@ -0,0 +1,21 @@ 
+[Unit]
+Description=Network Connectivity
+Wants=network.target
+Before=network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+
+# lo is brought up earlier, which will cause the upcoming "ifup -a" to fail
+# with exit code 1, due to an "ip: RTNETLINK answers: File exists" error during
+# its "ip addr add ..." command, subsequently causing this unit to fail even
+# though it is a benign error. Flushing the lo address with the command below
+# before ifup prevents this failure.
+ExecStart=/sbin/ip addr flush dev lo
+
+ExecStart=/sbin/ifup -a
+ExecStop=/sbin/ifdown -a
+
+[Install]
+WantedBy=multi-user.target
diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
index a5dc8e5..a99c0da 100644
--- a/package/systemd/systemd.mk
+++ b/package/systemd/systemd.mk
@@ -72,7 +72,16 @@  define SYSTEMD_INSTALL_TTY_HOOK
 	ln -fs ../../../../usr/lib/systemd/system/serial-getty@.service $(TARGET_DIR)/etc/systemd/system/getty.target.wants/serial-getty@$(BR2_TARGET_GENERIC_GETTY_PORT).service
 endef
 
+define SYSTEMD_INSTALL_NETWORK_HOOK
+	$(INSTALL) -D -m 644 package/systemd/network.service \
+		$(TARGET_DIR)/etc/systemd/system/network.service
+	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+	ln -fs ../network.service \
+		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/network.service
+endef
+
 SYSTEMD_POST_INSTALL_TARGET_HOOKS += \
 	SYSTEMD_INSTALL_TTY_HOOK \
+	SYSTEMD_INSTALL_NETWORK_HOOK
 
 $(eval $(autotools-package))