system: Add option to maintain a supervision tree
PATCH 1/1 system: Add option to maintain a supervision tree
One of the major drawbacks of classic init/rc systems is that dead daemons remain dead: Once started by the rc scripts, they are left to look after themselves.
A simple approach to keep them running reliably is to supervise them:
In a tree with PID 1 at its root, every process knows which children ought to run under it, and it respawns them accordingly. This is the supervision tree.
Classic init already provides rudimentary supervision in the form of inittab. This patch uses inittab to establish a more flexible supervision tree based on runit's rvsvdir or s6's s6-svscan.
BR2_TARGET_SUPERVISION_TREE could be extended to other init systems (systemd and OpenRC) as well, but I haven't done it because both of them have their own supervision features.
--- package/busybox/busybox.mk | 16 ++++++++++++++++ package/busybox/inittab | 3 +++ package/sysvinit/inittab | 3 +++ package/sysvinit/sysvinit.mk | 8 ++++++++ system/Config.in | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+)
package/busybox/busybox.mk +16 -0
@@ -229,6 +229,13 @@ define BUSYBOX_SET_INIT $(call KCONFIG_ENABLE_OPT,CONFIG_INIT) endef +ifeq ($(BR2_TARGET_SUPERVISION_TREE_RUNIT),y) +define BUSYBOX_SET_RUNIT + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSVDIR) + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSV) +endef +endif + ifeq ($(BR2_TARGET_GENERIC_GETTY),y) define BUSYBOX_SET_GETTY $(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(SYSTEM_GETTY_PORT)::respawn:/sbin/getty -L $(SYSTEM_GETTY_OPTIONS) $(SYSTEM_GETTY_PORT) $(SYSTEM_GETTY_BAUDRATE) $(SYSTEM_GETTY_TERM) #~' \
@@ -241,6 +248,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define BUSYBOX_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_SUPERVISOR +endif + BUSYBOX_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB endif # BR2_INIT_BUSYBOX
@@ -380,6 +395,7 @@ define BUSYBOX_KCONFIG_FIXUP_CMDS $(BUSYBOX_SET_CRYPT_SHA) $(BUSYBOX_LINUX_PAM) $(BUSYBOX_SET_INIT) + $(BUSYBOX_SET_RUNIT) $(BUSYBOX_SET_WATCHDOG) $(BUSYBOX_SET_SELINUX) $(BUSYBOX_SET_LESS_FLAGS)
package/busybox/inittab +3 -0
@@ -31,6 +31,9 @@ null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr # Put a getty on the serial port #ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #::ctrlaltdel:/sbin/reboot
package/sysvinit/inittab +3 -0
@@ -19,6 +19,9 @@ rcS:12345:wait:/etc/init.d/rcS # S0:1:respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#sv::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #ca::ctrlaltdel:/sbin/reboot
package/sysvinit/sysvinit.mk +8 -0
@@ -49,6 +49,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define SYSVINIT_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~sv::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_SUPERVISOR +endif + SYSVINIT_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB $(eval $(generic-package))
system/Config.in +33 -0
@@ -460,6 +460,39 @@ config BR2_TARGET_GENERIC_GETTY_OPTIONS Refer to getty --help for details. endif +menuconfig BR2_TARGET_SUPERVISION_TREE + bool "Maintain a process supervision tree at /var/service" + depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV + +if BR2_TARGET_SUPERVISION_TREE +choice + prompt "Supervisor" + +config BR2_TARGET_SUPERVISION_TREE_RUNIT + bool "runsvdir" + depends on BR2_PACKAGE_BUSYBOX + help + Use runsvdir (provided by the BusyBox package) to run the + supervision tree. + +config BR2_TARGET_SUPERVISION_TREE_S6 + bool "s6-svscan" + depends on BR2_USE_MMU # s6 + select BR2_PACKAGE_S6 + help + Use s6-svscan (provided by s6) to run the supervision tree. + +endchoice + +config BR2_TARGET_SUPERVISION_TREE_COMMAND + string + default "/usr/bin/runsvdir /var/service" if BR2_TARGET_SUPERVISION_TREE_RUNIT + default "/bin/s6-svscan /var/service" if BR2_TARGET_SUPERVISION_TREE_S6 +endif + +comment "process supervision tree needs sysv or busybox init" + depends on !BR2_INIT_BUSYBOX && !BR2_INIT_SYSV + config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW bool "remount root filesystem read-write during boot" default y
---
base-commit: 3ebc7c69d56430c34eba4c869d1d4fe4d1e8de55
change-id: 20240531-svtree-1925107719ce
Best regards,
--
J. Neuschäfer <[email protected]>
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Hi J.,
Quoted 4 lines · J. Neuschäfer via buildroot
One of the major drawbacks of classic init/rc systems is that dead daemons remain dead: Once started by the rc scripts, they are left to look after themselves.
Quoted 8 lines
A simple approach to keep them running reliably is to supervise them:
In a tree with PID 1 at its root, every process knows which children ought to run under it, and it respawns them accordingly. This is the supervision tree.Classic init already provides rudimentary supervision in the form of inittab. This patch uses inittab to establish a more flexible supervision tree based on runit's rvsvdir or s6's s6-svscan.
We discussed this patch here at the Buildroot hackaton. Although we fully
agree that having a supervisor is extremely useful, we also feel that this patch is very invasive for something that is relatively simple to implement at the moment. The only thing you need to do is to select the supervisor you want to use, and put a custom inittab in the filesystem overlay that starts the supervisor. Oh, and you probably also want a post-build script to remove everything in /etc/init.d for which you created a service instead - but that part isn't even handled by this patch.
One of Buildroot's main principles is keeping it simple. Over the years, we've
already collected way too much complexity. Therefore, we've decided to reject this patch.
Regardless, thank you for your contributions!
Regards,
Arnout
Quoted 151 lines
BR2_TARGET_SUPERVISION_TREEcould be extended to other init systems (systemd and OpenRC) as well, but I haven't done it because both of them have their own supervision features.Signed-off-by J. Neuschäfer <[email protected]>--- package/busybox/busybox.mk | 16 ++++++++++++++++ package/busybox/inittab | 3 +++ package/sysvinit/inittab | 3 +++ package/sysvinit/sysvinit.mk | 8 ++++++++ system/Config.in | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+)package/busybox/busybox.mk +16
-0@@ -229,6 +229,13 @@ define BUSYBOX_SET_INIT $(call KCONFIG_ENABLE_OPT,CONFIG_INIT) endef +ifeq ($(BR2_TARGET_SUPERVISION_TREE_RUNIT),y) +define BUSYBOX_SET_RUNIT + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSVDIR) + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSV) +endef +endif + ifeq ($(BR2_TARGET_GENERIC_GETTY),y) define BUSYBOX_SET_GETTY $(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(SYSTEM_GETTY_PORT)::respawn:/sbin/getty -L $(SYSTEM_GETTY_OPTIONS) $(SYSTEM_GETTY_PORT) $(SYSTEM_GETTY_BAUDRATE) $(SYSTEM_GETTY_TERM) #~' \@@ -241,6 +248,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define BUSYBOX_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_SUPERVISOR +endif + BUSYBOX_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB endif # BR2_INIT_BUSYBOX@@ -380,6 +395,7 @@ define BUSYBOX_KCONFIG_FIXUP_CMDS $(BUSYBOX_SET_CRYPT_SHA) $(BUSYBOX_LINUX_PAM) $(BUSYBOX_SET_INIT) + $(BUSYBOX_SET_RUNIT) $(BUSYBOX_SET_WATCHDOG) $(BUSYBOX_SET_SELINUX) $(BUSYBOX_SET_LESS_FLAGS)package/busybox/inittab +3
-0@@ -31,6 +31,9 @@ null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr # Put a getty on the serial port #ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #::ctrlaltdel:/sbin/rebootpackage/sysvinit/inittab +3
-0@@ -19,6 +19,9 @@ rcS:12345:wait:/etc/init.d/rcS # S0:1:respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#sv::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #ca::ctrlaltdel:/sbin/rebootpackage/sysvinit/sysvinit.mk +8
-0@@ -49,6 +49,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define SYSVINIT_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~sv::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_SUPERVISOR +endif + SYSVINIT_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB $(eval $(generic-package))system/Config.in +33
-1@@ -460,6 +460,39 @@ config BR2_TARGET_GENERIC_GETTY_OPTIONS Refer to getty --help for details. endif +menuconfig BR2_TARGET_SUPERVISION_TREE + bool "Maintain a process supervision tree at /var/service" + depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV + +if BR2_TARGET_SUPERVISION_TREE +choice + prompt "Supervisor" + +config BR2_TARGET_SUPERVISION_TREE_RUNIT + bool "runsvdir" + depends on BR2_PACKAGE_BUSYBOX + help + Use runsvdir (provided by the BusyBox package) to run the + supervision tree. + +config BR2_TARGET_SUPERVISION_TREE_S6 + bool "s6-svscan" + depends on BR2_USE_MMU # s6 + select BR2_PACKAGE_S6 + help + Use s6-svscan (provided by s6) to run the supervision tree. + +endchoice + +config BR2_TARGET_SUPERVISION_TREE_COMMAND + string + default "/usr/bin/runsvdir /var/service" if BR2_TARGET_SUPERVISION_TREE_RUNIT + default "/bin/s6-svscan /var/service" if BR2_TARGET_SUPERVISION_TREE_S6 +endif + +comment "process supervision tree needs sysv or busybox init" + depends on !BR2_INIT_BUSYBOX && !BR2_INIT_SYSV + config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW bool "remount root filesystem read-write during boot" default y ---base-commit:
3ebc7c69d56430c34eba4c869d1d4fe4d1e8de55
change-id: 20240531-svtree-1925107719ce
Quoted 8 lines
Best regards,
--
J. Neuschäfer <[email protected]>_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 25 lines · Arnout Vandecappelle
Hi J.,
Quoted 4 lines · J. Neuschäfer via buildroot
One of the major drawbacks of classic init/rc systems is that dead daemons remain dead: Once started by the rc scripts, they are left to look after themselves.
Quoted 8 lines
A simple approach to keep them running reliably is to supervise them:
In a tree with PID 1 at its root, every process knows which children ought to run under it, and it respawns them accordingly. This is the supervision tree.Classic init already provides rudimentary supervision in the form of inittab. This patch uses inittab to establish a more flexible supervision tree based on runit's rvsvdir or s6's s6-svscan.
We discussed this patch here at the Buildroot hackaton. Although we fully
agree that having a supervisor is extremely useful, we also feel that this patch is very invasive for something that is relatively simple to implement at the moment. The only thing you need to do is to select the supervisor you want to use, and put a custom inittab in the filesystem overlay that starts the supervisor. Oh, and you probably also want a post-build script to remove everything in/etc/init.dfor which you created a service instead - but that part isn't even handled by this patch.
Quoted 3 lines
One of Buildroot's main principles is keeping it simple. Over the years,
we've already collected way too much complexity. Therefore, we've decided to reject this patch.
Fair enough -- the particular design trade-offs can be a bit difficult to see from the outside. For example (and this is not a reason to merge my patch, just an explanation of my thought process), adding a custom inittab requires knowing/copying the whole inittab, whereas the user of this option would only need to know that they want a supervision tree, which is from that perspective simpler.
Quoted 2 lines
Regardless, thank you for your contributions!
Again, thank you for your thoughtful and friendly reviews :)
-- jn
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 13 lines · J. Neuschäfer via buildroot
One of the major drawbacks of classic init/rc systems is that dead daemons remain dead: Once started by the rc scripts, they are left to look after themselves.
A simple approach to keep them running reliably is to supervise them:
In a tree with PID 1 at its root, every process knows which children ought to run under it, and it respawns them accordingly. This is the supervision tree.Classic init already provides rudimentary supervision in the form of inittab. This patch uses inittab to establish a more flexible supervision tree based on runit's rvsvdir or s6's s6-svscan.
Quoted 5 lines
BR2_TARGET_SUPERVISION_TREEcould be extended to other init systems (systemd and OpenRC) as well, but I haven't done it because both of them have their own supervision features.Signed-off-by J. Neuschäfer <[email protected]>
Applied to master, thanks.
Regards,
Arnout
Quoted 145 lines
--- package/busybox/busybox.mk | 16 ++++++++++++++++ package/busybox/inittab | 3 +++ package/sysvinit/inittab | 3 +++ package/sysvinit/sysvinit.mk | 8 ++++++++ system/Config.in | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+)package/busybox/busybox.mk +16
-0@@ -229,6 +229,13 @@ define BUSYBOX_SET_INIT $(call KCONFIG_ENABLE_OPT,CONFIG_INIT) endef +ifeq ($(BR2_TARGET_SUPERVISION_TREE_RUNIT),y) +define BUSYBOX_SET_RUNIT + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSVDIR) + $(call KCONFIG_ENABLE_OPT,CONFIG_RUNSV) +endef +endif + ifeq ($(BR2_TARGET_GENERIC_GETTY),y) define BUSYBOX_SET_GETTY $(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(SYSTEM_GETTY_PORT)::respawn:/sbin/getty -L $(SYSTEM_GETTY_OPTIONS) $(SYSTEM_GETTY_PORT) $(SYSTEM_GETTY_BAUDRATE) $(SYSTEM_GETTY_TERM) #~' \@@ -241,6 +248,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define BUSYBOX_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_SUPERVISOR +endif + BUSYBOX_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB endif # BR2_INIT_BUSYBOX@@ -380,6 +395,7 @@ define BUSYBOX_KCONFIG_FIXUP_CMDS $(BUSYBOX_SET_CRYPT_SHA) $(BUSYBOX_LINUX_PAM) $(BUSYBOX_SET_INIT) + $(BUSYBOX_SET_RUNIT) $(BUSYBOX_SET_WATCHDOG) $(BUSYBOX_SET_SELINUX) $(BUSYBOX_SET_LESS_FLAGS)package/busybox/inittab +3
-0@@ -31,6 +31,9 @@ null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr # Put a getty on the serial port #ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #::ctrlaltdel:/sbin/rebootpackage/sysvinit/inittab +3
-0@@ -19,6 +19,9 @@ rcS:12345:wait:/etc/init.d/rcS # S0:1:respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL +# Maintain a supervision tree +#sv::respawn:/bin/runsvdir /var/service # SUPERVISION_TREE + # Stuff to do for the 3-finger salute #ca::ctrlaltdel:/sbin/rebootpackage/sysvinit/sysvinit.mk +8
-0@@ -49,6 +49,14 @@ endef endif # BR2_TARGET_GENERIC_GETTY SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_GETTY +ifeq ($(BR2_TARGET_SUPERVISION_TREE),y) +define SYSVINIT_SET_SUPERVISOR + $(SED) '/# SUPERVISION_TREE$$/s~^.*#~sv::respawn:$(call qstrip,$(BR2_TARGET_SUPERVISION_TREE_COMMAND)) #~' $(TARGET_DIR)/etc/inittab + mkdir -p $(TARGET_DIR)/var/service +endef +SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_SUPERVISOR +endif + SYSVINIT_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB $(eval $(generic-package))system/Config.in +33
-1@@ -460,6 +460,39 @@ config BR2_TARGET_GENERIC_GETTY_OPTIONS Refer to getty --help for details. endif +menuconfig BR2_TARGET_SUPERVISION_TREE + bool "Maintain a process supervision tree at /var/service" + depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV + +if BR2_TARGET_SUPERVISION_TREE +choice + prompt "Supervisor" + +config BR2_TARGET_SUPERVISION_TREE_RUNIT + bool "runsvdir" + depends on BR2_PACKAGE_BUSYBOX + help + Use runsvdir (provided by the BusyBox package) to run the + supervision tree. + +config BR2_TARGET_SUPERVISION_TREE_S6 + bool "s6-svscan" + depends on BR2_USE_MMU # s6 + select BR2_PACKAGE_S6 + help + Use s6-svscan (provided by s6) to run the supervision tree. + +endchoice + +config BR2_TARGET_SUPERVISION_TREE_COMMAND + string + default "/usr/bin/runsvdir /var/service" if BR2_TARGET_SUPERVISION_TREE_RUNIT + default "/bin/s6-svscan /var/service" if BR2_TARGET_SUPERVISION_TREE_S6 +endif + +comment "process supervision tree needs sysv or busybox init" + depends on !BR2_INIT_BUSYBOX && !BR2_INIT_SYSV + config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW bool "remount root filesystem read-write during boot" default y ---base-commit:
3ebc7c69d56430c34eba4c869d1d4fe4d1e8de55
change-id: 20240531-svtree-1925107719ce
Quoted 8 lines
Best regards,
--
J. Neuschäfer <[email protected]>_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot