Skip to contentSkip to conversation

systemd: add network unit file

PATCH New Eric Le Bihan 3 participants 4 messages Jun 13, 2014 – Jun 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 systemd: add network unit file

From: Ivan Sergeev <[email protected]>

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.

[eric.le.bihan.dev at free.fr:
- rebase
- install service only if systemd-networkd is not selected]

---
 package/systemd/network.service |   21 +++++++++++++++++++++
 package/systemd/systemd.mk      |   12 ++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 package/systemd/network.service
package/systemd/network.service new file +21 -0
new file mode 100644
index 0000000..0d77bb8
@@ -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
package/systemd/systemd.mk +12 -0
index 6de7887..f3874db 100644
@@ -145,12 +145,24 @@ define SYSTEMD_SANITIZE_PATH_IN_UNITS
 		-exec $(SED) 's,$(HOST_DIR),,g' {} \;
 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_INIT_HOOK \
 	SYSTEMD_INSTALL_TTY_HOOK \
 	SYSTEMD_INSTALL_MACHINEID_HOOK \
 	SYSTEMD_SANITIZE_PATH_IN_UNITS
 
+ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),)
+SYSTEMD_POST_INSTALL_TARGET_HOOKS += SYSTEMD_INSTALL_NETWORK_HOOK
+endif
+
 define SYSTEMD_USERS
 	systemd-journal -1 systemd-journal -1 * /var/log/journal - - Journal
 	systemd-journal-gateway -1 systemd-journal-gateway -1 * /var/log/journal - - Journal Gateway
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 systemd: add network unit file

Dear Eric Le Bihan,

Quoted 9 lines · Eric Le Bihan

From: Ivan Sergeev <[email protected]>

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.

[eric.le.bihan.dev at free.fr:
- rebase
- install service only if systemd-networkd is not selected]

Quoted 6 lines
---
 package/systemd/network.service |   21 +++++++++++++++++++++
 package/systemd/systemd.mk      |   12 ++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 package/systemd/network.service

Applied, thanks. However, I have a comment/question, below.

Quoted 7 lines
package/systemd/systemd.mk +7 -0
+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

package/systemd/systemd.mk define SYSTEMD_SANITIZE_PATH_IN_UNITS · line 164

Quoted 10 lines
package/systemd/systemd.mk +4 -0
+
 SYSTEMD_POST_INSTALL_TARGET_HOOKS += \
 	SYSTEMD_INSTALL_INIT_HOOK \
 	SYSTEMD_INSTALL_TTY_HOOK \
 	SYSTEMD_INSTALL_MACHINEID_HOOK \
 	SYSTEMD_SANITIZE_PATH_IN_UNITS
 
+ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),)
+SYSTEMD_POST_INSTALL_TARGET_HOOKS += SYSTEMD_INSTALL_NETWORK_HOOK
+endif

I'm wondering why we're not using the <pkg>_INIT_SYSTEMD mechanism here.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 systemd: add network unit file

Hi!

Quoted 36 lines · Thomas Petazzoni

Dear Eric Le Bihan,

Quoted 9 lines · Eric Le Bihan

From: Ivan Sergeev <[email protected]>

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.

[eric.le.bihan.dev at free.fr:
- rebase
- install service only if systemd-networkd is not selected]

Quoted 6 lines
---
 package/systemd/network.service |   21 +++++++++++++++++++++
 package/systemd/systemd.mk      |   12 ++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 package/systemd/network.service

Applied, thanks. However, I have a comment/question, below.

Quoted 14 lines
package/systemd/systemd.mk +8 -0
+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_INIT_HOOK \
 	SYSTEMD_INSTALL_TTY_HOOK \
 	SYSTEMD_INSTALL_MACHINEID_HOOK \
 	SYSTEMD_SANITIZE_PATH_IN_UNITS
Quoted 5 lines

package/systemd/systemd.mk define SYSTEMD_SANITIZE_PATH_IN_UNITS · line 164

Quoted 3 lines
package/systemd/systemd.mk +3 -0
+ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),)
+SYSTEMD_POST_INSTALL_TARGET_HOOKS += SYSTEMD_INSTALL_NETWORK_HOOK
+endif

I'm wondering why we're not using the <pkg>_INIT_SYSTEMD mechanism here.

Good suggestion! I'll send a patch with the weird "SYSTEMD_INSTALL_INIT_SYSTEMD" and the cosmetic fix suggested by Yann E. Morin.

Best regards,
ELB

#3 lore raw

PATCH 1/1 systemd: add network unit file

In reply to Eric Le Bihan

Eric, All,

On 2014-06-13 17:35 +0200, Eric Le Bihan spake thusly:

Quoted 4 lines

From: Ivan Sergeev <[email protected]>

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.

[--SNIP--]

Quoted 16 lines
package/systemd/systemd.mk +8 -0
index 6de7887..f3874db 100644
@@ -145,12 +145,24 @@ define SYSTEMD_SANITIZE_PATH_IN_UNITS
 		-exec $(SED) 's,$(HOST_DIR),,g' {} \;
 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
+

package/systemd/systemd.mk define SYSTEMD_SANITIZE_PATH_IN_UNITS · line 165

Quoted 10 lines
package/systemd/systemd.mk +4 -0
 SYSTEMD_POST_INSTALL_TARGET_HOOKS += \
 	SYSTEMD_INSTALL_INIT_HOOK \
 	SYSTEMD_INSTALL_TTY_HOOK \
 	SYSTEMD_INSTALL_MACHINEID_HOOK \
 	SYSTEMD_SANITIZE_PATH_IN_UNITS
 
+ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),)
+SYSTEMD_POST_INSTALL_TARGET_HOOKS += SYSTEMD_INSTALL_NETWORK_HOOK
+endif
+

I thought we said the hook definitions should be part of the conditional block?

http://buildroot.net/downloads/manual/manual.html#writing-rules-mk

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'