Skip to contentSkip to conversation

skeleton: add systemd network.service unit

PATCH New Ivan Sergeev 7 participants 15 messages Jan 3, 2014 – Jun 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Add and enable a systemd unit file to bring up / down network with ifup / ifdown, analogous to the skeleton/etc/init.d/S40network init script.

---
 .../system/multi-user.target.wants/network.service  |  1 +
 system/skeleton/etc/systemd/system/network.service  | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 120000 system/skeleton/etc/systemd/system/multi-user.target.wants/network.service
 create mode 100644 system/skeleton/etc/systemd/system/network.service
system/skeleton/etc/systemd/system/multi-user.target.wants/network.service new file +1 -0
new file mode 120000
index 0000000..d3558f9
@@ -0,0 +1 @@
+../network.service
\ No newline at end of file
system/skeleton/etc/systemd/system/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
Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Dear Ivan Sergeev,

Quoted 10 lines · Ivan Sergeev

Add and enable a systemd unit file to bring up / down network with ifup / ifdown, analogous to the skeleton/etc/init.d/S40network init script.

---
 .../system/multi-user.target.wants/network.service  |  1 +
 system/skeleton/etc/systemd/system/network.service  | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 120000 system/skeleton/etc/systemd/system/multi-user.target.wants/network.service
 create mode 100644 system/skeleton/etc/systemd/system/network.service

We probably want to make that conditional on the type of init system that is used, no?

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 skeleton: add systemd network.service unit

Hah, sorry. I forgot the reply all. This was supposed to be my follow up discussion email:

Hello buildroot,

I'm submitting this in hopes of catching up network init in systemd with that of busybox init, which is currently served by /etc/init.d/S40network. This patch adds and enables network.service (which assumes ifup / ifdown exists and uses them like /etc/init.d/S40network does).

I also wanted to bring up a more general issue:

Currently, it seems that the /etc/init.d scripts are copied over blindly from the target skeleton to the target even if systemd (and not busybox) is the chosen init system. Moving forward, having both busybox and systemd init files in the skeleton, like this patch would have, will always clutter /etc/ with some unused init files in the target system, since only one init system will be active.

Should such init files be conditional targets in system/system.mk? Or should S40network be owned and copied over by package/busybox, and network.service be owned and copied over by package/systemd, instead of having them included statically in the target skeleton?

Thanks,
~vsergeev
Ivan Sergeev

Quoted 16 lines · Thomas Petazzoni

Dear Ivan Sergeev,

Quoted 7 lines · Ivan Sergeev

Add and enable a systemd unit file to bring up / down network with ifup / ifdown, analogous to the skeleton/etc/init.d/S40network init script.

---
 .../system/multi-user.target.wants/network.service  |  1 +
 system/skeleton/etc/systemd/system/network.service  | 21

+++++++++++++++++++++

Quoted 2 lines
 2 files changed, 22 insertions(+)
 create mode 120000

system/skeleton/etc/systemd/system/multi-user.target.wants/network.service

Quoted 1 line
 create mode 100644 system/skeleton/etc/systemd/system/network.service
Quoted 9 lines

We probably want to make that conditional on the type of init system that is used, no?

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20140103/5487751a/attachment.html>

#3 lore raw

PATCH 1/1 systemd: add network unit file

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.

---
 package/systemd/network.service | 21 +++++++++++++++++++++
 package/systemd/systemd.mk      |  9 +++++++++
 2 files changed, 30 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 +9 -0
index a5dc8e5..a99c0da 100644
@@ -72,7 +72,16 @@ define SYSTEMD_INSTALL_TTY_HOOK
 	ln -fs ../../../../usr/lib/systemd/system/serial-getty at .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))
Signature · 1 line
1.8.5.3
#4 lore raw

PATCH 1/1 systemd: add network unit file

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

Quoted 58 lines · Ivan Sergeev

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.

---
 package/systemd/network.service | 21 +++++++++++++++++++++
 package/systemd/systemd.mk      |  9 +++++++++
 2 files changed, 30 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 +9 -0
index a5dc8e5..a99c0da 100644
@@ -72,7 +72,16 @@ define SYSTEMD_INSTALL_TTY_HOOK
 	ln -fs ../../../../usr/lib/systemd/system/serial-getty at .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))
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#5 lore raw

PATCH 1/1 systemd: add network unit file

Thomas, Ivan,

Quoted 5 lines · Thomas Petazzoni

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

#6 lore raw

PATCH 1/1 systemd: add network unit file

Dear Eric Le Bihan,

Quoted 7 lines · Eric Le Bihan

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

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

PATCH 1/1 skeleton: add systemd network.service unit

In reply to Ivan Sergeev
Quoted 7 lines · Ivan Sergeev

Currently, it seems that the /etc/init.d scripts are copied over blindly from the target skeleton to the target even if systemd (and not busybox) is the chosen init system. Moving forward, having both busybox and systemd init files in the skeleton, like this patch would have, will always clutter /etc/ with some unused init files in the target system, since only one init system will be active.

Quoted 5 lines

Should such init files be conditional targets in system/system.mk ? Or should S40network be owned and copied over by package/busybox, and network.service be owned and copied over by package/systemd, instead of having them included statically in the target skeleton?

I completely agree that the way it is done now is far from ideal.

I think the best way to work with this would be to:

- remove the contents of the init.d directory from the skeleton;

- create a new skeleton fragment system/skeleton-init-sysv that contains etc/init.d;

- create a new skeleton fragment system/skeleton-init-systemd that contains whatever support files are needed by systemd (currently nothing, but your patch would add the networking unit file);

- copy the correct skeleton fragment as part of the .root target, but only if the default skeleton was selected - with a custom skeleton, it's up to the user to provide the right systemd/init.d;

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#8 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Hi all

Quoted 25 lines · Arnout Vandecappelle
Quoted 8 lines · Ivan Sergeev

Currently, it seems that the /etc/init.d scripts are copied over blindly from the target skeleton to the target even if systemd (and not busybox) is the chosen init system. Moving forward, having both busybox and systemd init files in the skeleton, like this patch would have, will always clutter /etc/ with some unused init files in the target system, since only one init system will be active.

Quoted 5 lines

Should such init files be conditional targets in system/system.mk ? Or should S40network be owned and copied over by package/busybox, and network.service be owned and copied over by package/systemd, instead of having them included statically in the target skeleton?

I completely agree that the way it is done now is far from ideal.

I think the best way to work with this would be to:

- remove the contents of the init.d directory from the skeleton;

- create a new skeleton fragment system/skeleton-init-sysv that contains etc/init.d;

Quoted 7 lines

- create a new skeleton fragment system/skeleton-init-systemd that contains whatever support files are needed by systemd (currently nothing, but your patch would add the networking unit file);

- copy the correct skeleton fragment as part of the .root target, but only if the default skeleton was selected - with a custom skeleton, it's up to the user to provide the right systemd/init.d;

I agree with you and as a matter of fact, I had already started working on a patch that implement exactly this.

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Quoted 18 lines

Regards,
Arnout

--

Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#9 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Quoted 42 lines · Maxime Hadjinlian

Hi all

Quoted 9 lines · Arnout Vandecappelle
Quoted 8 lines · Ivan Sergeev

Currently, it seems that the /etc/init.d scripts are copied over blindly from the target skeleton to the target even if systemd (and not busybox) is the chosen init system. Moving forward, having both busybox and systemd init files in the skeleton, like this patch would have, will always clutter /etc/ with some unused init files in the target system, since only one init system will be active.

Quoted 4 lines
Quoted 4 lines

Should such init files be conditional targets in system/system.mk ? Or should S40network be owned and copied over by package/busybox, and network.service be owned and copied over by package/systemd, instead of having them included statically in the

target

Quoted 5 lines
Quoted 1 line

skeleton?

I completely agree that the way it is done now is far from ideal.

Quoted 8 lines

I think the best way to work with this would be to:

- remove the contents of the init.d directory from the skeleton;

- create a new skeleton fragment system/skeleton-init-sysv that contains etc/init.d;

- create a new skeleton fragment system/skeleton-init-systemd that

contains

Quoted 4 lines

whatever support files are needed by systemd (currently nothing, but your patch would add the networking unit file);

- copy the correct skeleton fragment as part of the .root target, but

only

Quoted 2 lines

if the default skeleton was selected - with a custom skeleton, it's up to the user to provide the right systemd/init.d;

I agree with you and as a matter of fact, I had already started working on a patch that implement exactly this.

Quoted 6 lines

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

Sounds like a great idea!

Quoted 4 lines

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Probably the whole INSTALL_INIT_* stuff can even be removed - the
number of packages that require special-casing is currently zero and may not ever be larger than zero. And if they do, it's not that difficult to make conditional post-install hooks.

If you make a patch, don't forget to update the documentation!

Regards,
Arnout

Quoted 19 lines
Quoted 19 lines

Regards,
Arnout

--

Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 6 lines
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#10 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

In reply to Maxime Hadjinlian
Quoted 10 lines · Maxime Hadjinlian

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Actually, there's two main issues that prevents this in the systemd case, and are why we did it that way:
- the multi-user-wants thing is actually comparable to the sysvinit runlevels. Some packages might want to set their units to other targets than multi-user (for example, graphical applications are likely to go in the graphical target, not the multi-user one)
- Some units also takes "variables" from the created link names. For example, when you want to run getty, you just have a single getty unit, and the device to run getty on is set in the link name to that unit (so you'd end up with a link in multi-user.target.wants that will be getty.ttyS0.service, linking to /etc/systemd/system/getty.service).

At the time, we thought that in the systemd case, the easiest would be to simply write down the 2-3 commands we need to setup the unit, instead of having to give a whole bunch of variables. And we did the same for sysvinit scripts, for consistency.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20140128/bad2adac/attachment.asc>
#11 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Quoted 12 lines · Maxime Ripard
Quoted 10 lines · Maxime Hadjinlian

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Quoted 6 lines

Actually, there's two main issues that prevents this in the systemd case, and are why we did it that way:
- the multi-user-wants thing is actually comparable to the sysvinit runlevels. Some packages might want to set their units to other targets than multi-user (for example, graphical applications are likely to go in the graphical target, not the multi-user one)

I disagree with this one. Buildroot's defaults should support only a
single runlevel/target. That's how it's done for sysv init, and I'm very happy with it: it's dead easy to see which scripts will be executed at startup, you don't have to find out the runlevel etc. With systemd, things can become even more complex (because there can be several "targets" active at the same time IIRC), and I'd prefer to exclude this complexity by default.

If a user requires several runlevels/targets, than most likely any
default that buildroot provide will not fit anyway, so the user will have to manipulate things in their rootfs overlay or post-build script anyway. Therefore, I think it is better for the user if the defaults are simple and predictable.

Quoted 6 lines

- Some units also takes "variables" from the created link names. For example, when you want to run getty, you just have a single getty unit, and the device to run getty on is set in the link name to that unit (so you'd end up with a link in multi-user.target.wants that will be getty.ttyS0.service, linking to /etc/systemd/system/getty.service).

That is one of the special cases that would be handled in a
post-install hook. But specifically for the getty case, it's not even necessary because we start only a single getty in the default setup, so we can directly install it to getty at ttyS0.service .

Quoted 4 lines

At the time, we thought that in the systemd case, the easiest would be to simply write down the 2-3 commands we need to setup the unit, instead of having to give a whole bunch of variables. And we did the same for sysvinit scripts, for consistency.

I think at the time, we mainly thought that we didn't know yet if the
installation could be generalized. Now that we have a few packages that install unit files, it's more clear that they always to the same.

Also, as far as I understand, the idea is not to add variables, but
rather to check for the existence of package/foo/*.service and install that.

Regards,
Arnout

Quoted 3 lines

Maxime

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#12 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Quoted 20 lines · Arnout Vandecappelle
Quoted 12 lines · Maxime Ripard
Quoted 10 lines · Maxime Hadjinlian

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Quoted 6 lines

Actually, there's two main issues that prevents this in the systemd case, and are why we did it that way:
- the multi-user-wants thing is actually comparable to the sysvinit runlevels. Some packages might want to set their units to other targets than multi-user (for example, graphical applications are likely to go in the graphical target, not the multi-user one)

Quoted 2 lines

I disagree with this one. Buildroot's defaults should support only
a single runlevel/target. That's how it's done for sysv init, and

Hmm, afaik, it's not done at all in the sysvinit case, because the default sysvinit we use most of the time (busybox's) doesn't handle the runlevel at all. It's not really the same story there.

Quoted 20 lines

I'm very happy with it: it's dead easy to see which scripts will be executed at startup, you don't have to find out the runlevel etc. With systemd, things can become even more complex (because there can be several "targets" active at the same time IIRC), and I'd prefer to exclude this complexity by default.

If a user requires several runlevels/targets, than most likely any
default that buildroot provide will not fit anyway, so the user will have to manipulate things in their rootfs overlay or post-build script anyway. Therefore, I think it is better for the user if the defaults are simple and predictable.

Quoted 6 lines

- Some units also takes "variables" from the created link names. For example, when you want to run getty, you just have a single getty unit, and the device to run getty on is set in the link name to that unit (so you'd end up with a link in multi-user.target.wants that will be getty.ttyS0.service, linking to /etc/systemd/system/getty.service).

Quoted 4 lines

That is one of the special cases that would be handled in a
post-install hook. But specifically for the getty case, it's not even necessary because we start only a single getty in the default setup, so we can directly install it to getty at ttyS0.service .

Which won't work if you don't have a different tty to export a shell on, but yes, I get your point.

Quoted 9 lines
Quoted 4 lines

At the time, we thought that in the systemd case, the easiest would be to simply write down the 2-3 commands we need to setup the unit, instead of having to give a whole bunch of variables. And we did the same for sysvinit scripts, for consistency.

I think at the time, we mainly thought that we didn't know yet if
the installation could be generalized. Now that we have a few packages that install unit files, it's more clear that they always to the same.

We have *three* packages with systemd units in current master. I hardly see how you can generalize something out of 3 (similar) samples.

Quoted 3 lines

Also, as far as I understand, the idea is not to add variables, but
rather to check for the existence of package/foo/*.service and install that.

This also doesn't cover the case anymore where a package would ship together with the source code a systemd unit file. I expect it to be more and more common, and it's something that we will want to use most of the time, and not duplicate the unit file in the buildroot package itself.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20140129/07705c21/attachment.asc>
#13 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

Quoted 63 lines · Maxime Ripard
Quoted 20 lines · Arnout Vandecappelle
Quoted 12 lines · Maxime Ripard
Quoted 10 lines · Maxime Hadjinlian

I would even like to go even further, as I have noticed that a lot of the defined LIBFOO_INSTALL_INIT_SYSTEMD and LIBFOO_INSTALL_INIT_SYSV almost always do the exact same stuff.
I would like for the infrastructure to take care of this, if no function is defined, and a .service or S\d{0,2}*, then we should take it and install it.

In that case, any particular requirements, the package define a function, other than that, it's taken care of and we avoid duplicate code in all the packages.

Quoted 6 lines

Actually, there's two main issues that prevents this in the systemd case, and are why we did it that way:
- the multi-user-wants thing is actually comparable to the sysvinit runlevels. Some packages might want to set their units to other targets than multi-user (for example, graphical applications are likely to go in the graphical target, not the multi-user one)

Quoted 2 lines

I disagree with this one. Buildroot's defaults should support only
a single runlevel/target. That's how it's done for sysv init, and

Hmm, afaik, it's not done at all in the sysvinit case, because the default sysvinit we use most of the time (busybox's) doesn't handle the runlevel at all. It's not really the same story there.

Quoted 20 lines

I'm very happy with it: it's dead easy to see which scripts will be executed at startup, you don't have to find out the runlevel etc. With systemd, things can become even more complex (because there can be several "targets" active at the same time IIRC), and I'd prefer to exclude this complexity by default.

If a user requires several runlevels/targets, than most likely any
default that buildroot provide will not fit anyway, so the user will have to manipulate things in their rootfs overlay or post-build script anyway. Therefore, I think it is better for the user if the defaults are simple and predictable.

Quoted 6 lines

- Some units also takes "variables" from the created link names. For example, when you want to run getty, you just have a single getty unit, and the device to run getty on is set in the link name to that unit (so you'd end up with a link in multi-user.target.wants that will be getty.ttyS0.service, linking to /etc/systemd/system/getty.service).

Quoted 4 lines

That is one of the special cases that would be handled in a
post-install hook. But specifically for the getty case, it's not even necessary because we start only a single getty in the default setup, so we can directly install it to getty at ttyS0.service .

Which won't work if you don't have a different tty to export a shell on, but yes, I get your point.

Quoted 5 lines
Quoted 4 lines

At the time, we thought that in the systemd case, the easiest would be to simply write down the 2-3 commands we need to setup the unit, instead of having to give a whole bunch of variables. And we did the same for sysvinit scripts, for consistency.

Quoted 8 lines
Quoted 4 lines

I think at the time, we mainly thought that we didn't know yet if
the installation could be generalized. Now that we have a few packages that install unit files, it's more clear that they always to the same.

We have *three* packages with systemd units in current master. I hardly see how you can generalize something out of 3 (similar) samples.

Well to be fair, a *lot* of startup script (Whatever if it's SysV, systemd, or another one), it is usually a single file starting a binary with command line arguments. Nothing really fancy.

Quoted 10 lines
Quoted 4 lines

Also, as far as I understand, the idea is not to add variables, but
rather to check for the existence of package/foo/*.service and install that.

This also doesn't cover the case anymore where a package would ship together with the source code a systemd unit file. I expect it to be more and more common, and it's something that we will want to use most of the time, and not duplicate the unit file in the buildroot package itself.

If a package ship with the unit file in its source code, there should be a way to install it using the package configure/make or whatever is provided for that. So you won't even copy the file, we won't need a copy. Or if it's not possible, we would define the helper function, and it will install it, which would avoid the copy again.

Quoted 7 lines

Maxime

--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

#14 lore raw

PATCH 1/1 skeleton: add systemd network.service unit

In reply to Maxime Ripard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Maxime" == Maxime Ripard <[email protected]> writes:

Hi,

Quoted 9 lines
Quoted 3 lines

Also, as far as I understand, the idea is not to add variables, but rather to check for the existence of package/foo/*.service and install that.

This also doesn't cover the case anymore where a package would ship together with the source code a systemd unit file. I expect it to be more and more common, and it's something that we will want to use most of the time, and not duplicate the unit file in the buildroot package itself.

Good point. I would certainly not want us to write our own service files if upstream provides a workable one.

Signature · 1 line
Bye, Peter Korsgaard