Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] systemd: add network unit file
@ 2014-06-13 15:35 Eric Le Bihan
  2014-06-14 16:42 ` Thomas Petazzoni
  2014-06-14 16:50 ` Yann E. MORIN
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Le Bihan @ 2014-06-13 15:35 UTC (permalink / raw)
  To: buildroot

From: Ivan Sergeev <vsergeev@kumunetworks.com>

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>
[eric.le.bihan.dev at free.fr:
  - rebase
  - install service only if systemd-networkd is not selected]
Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr>
---
 package/systemd/network.service |   21 +++++++++++++++++++++
 package/systemd/systemd.mk      |   12 ++++++++++++
 2 files changed, 33 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 6de7887..f3874db 100644
--- a/package/systemd/systemd.mk
+++ b/package/systemd/systemd.mk
@@ -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
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH] systemd: add network unit file
  2014-06-13 15:35 [Buildroot] [PATCH] systemd: add network unit file Eric Le Bihan
@ 2014-06-14 16:42 ` Thomas Petazzoni
  2014-06-16 20:49   ` Eric Le Bihan
  2014-06-14 16:50 ` Yann E. MORIN
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2014-06-14 16:42 UTC (permalink / raw)
  To: buildroot

Dear Eric Le Bihan,

On Fri, 13 Jun 2014 17:35:35 +0200, Eric Le Bihan wrote:
> From: Ivan Sergeev <vsergeev@kumunetworks.com>
> 
> 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>
> [eric.le.bihan.dev at free.fr:
>   - rebase
>   - install service only if systemd-networkd is not selected]
> Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr>
> ---
>  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.


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

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

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH] systemd: add network unit file
  2014-06-13 15:35 [Buildroot] [PATCH] systemd: add network unit file Eric Le Bihan
  2014-06-14 16:42 ` Thomas Petazzoni
@ 2014-06-14 16:50 ` Yann E. MORIN
  1 sibling, 0 replies; 4+ messages in thread
From: Yann E. MORIN @ 2014-06-14 16:50 UTC (permalink / raw)
  To: buildroot

Eric, All,

On 2014-06-13 17:35 +0200, Eric Le Bihan spake thusly:
> From: Ivan Sergeev <vsergeev@kumunetworks.com>
> 
> 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--]
> diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> index 6de7887..f3874db 100644
> --- a/package/systemd/systemd.mk
> +++ b/package/systemd/systemd.mk
> @@ -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
> +

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.

-- 
.-----------------.--------------------.------------------.--------------------.
|  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.  |
'------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH] systemd: add network unit file
  2014-06-14 16:42 ` Thomas Petazzoni
@ 2014-06-16 20:49   ` Eric Le Bihan
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Le Bihan @ 2014-06-16 20:49 UTC (permalink / raw)
  To: buildroot

Hi!
On Sat, Jun 14, 2014 at 06:42:06PM +0200, Thomas Petazzoni wrote:
> Dear Eric Le Bihan,
>
> On Fri, 13 Jun 2014 17:35:35 +0200, Eric Le Bihan wrote:
> > From: Ivan Sergeev <vsergeev@kumunetworks.com>
> >
> > 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>
> > [eric.le.bihan.dev at free.fr:
> >   - rebase
> >   - install service only if systemd-networkd is not selected]
> > Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr>
> > ---
> >  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.
>
>
> > +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
>
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-16 20:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-13 15:35 [Buildroot] [PATCH] systemd: add network unit file Eric Le Bihan
2014-06-14 16:42 ` Thomas Petazzoni
2014-06-16 20:49   ` Eric Le Bihan
2014-06-14 16:50 ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox