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 Superseded
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
Thomas Petazzoni - June 11, 2014, 8:34 p.m.
Eric,

As our systemd person, could you have a look at this patch, and give
your comments and/or Acked-by/Reviewed-by as appropriate?

Thanks!

Thomas

On Mon, 27 Jan 2014 17:54:57 -0800, Ivan Sergeev wrote:
> 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
> 
> 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))
Eric Le Bihan - June 13, 2014, 3:42 p.m.
Thomas, Ivan,

On Wed, Jun 11, 2014 at 10:34:47PM +0200, Thomas Petazzoni wrote:
> Eric,
>
> As our systemd person, could you have a look at this patch, and give
> your comments and/or Acked-by/Reviewed-by as appropriate?
>
I've tested the patch. It is OK, but I made some modifications:

- rebase
- the new network.service is not installed if systemd-networkd is selected, as
  they conflict.

The updated version can be found at http://patchwork.ozlabs.org/patch/359561/.

Best regards,
ELB
Thomas Petazzoni - June 13, 2014, 3:44 p.m.
Dear Eric Le Bihan,

On Fri, 13 Jun 2014 17:42:43 +0200, Eric Le Bihan wrote:

> I've tested the patch. It is OK, but I made some modifications:
> 
> - rebase
> - the new network.service is not installed if systemd-networkd is selected, as
>   they conflict.
> 
> The updated version can be found at http://patchwork.ozlabs.org/patch/359561/.

Thanks, I've marked Ivan's patch as superseded in patchwork.

Thanks a lot for working on this!

Thomas

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))