Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] system: Add option to maintain a supervision tree
@ 2024-07-04 19:00 J. Neuschäfer via buildroot
  2024-07-14 21:11 ` Arnout Vandecappelle via buildroot
  2024-07-14 22:12 ` Arnout Vandecappelle via buildroot
  0 siblings, 2 replies; 4+ messages in thread
From: J. Neuschäfer via buildroot @ 2024-07-04 19:00 UTC (permalink / raw)
  To: buildroot; +Cc: J. Neuschäfer

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.

Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
---
 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(+)

diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index eb5e7ad922..31231bfc92 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -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)
diff --git a/package/busybox/inittab b/package/busybox/inittab
index f2b4df801b..8bed294019 100644
--- a/package/busybox/inittab
+++ b/package/busybox/inittab
@@ -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

diff --git a/package/sysvinit/inittab b/package/sysvinit/inittab
index afc28e6c03..e70684fade 100644
--- a/package/sysvinit/inittab
+++ b/package/sysvinit/inittab
@@ -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

diff --git a/package/sysvinit/sysvinit.mk b/package/sysvinit/sysvinit.mk
index 7f37cea131..16509dd622 100644
--- a/package/sysvinit/sysvinit.mk
+++ b/package/sysvinit/sysvinit.mk
@@ -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))
diff --git a/system/Config.in b/system/Config.in
index 3fb17ed1c6..bb88f276ec 100644
--- a/system/Config.in
+++ b/system/Config.in
@@ -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 <j.neuschaefer@gmx.net>

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] system: Add option to maintain a supervision tree
  2024-07-04 19:00 [Buildroot] [PATCH] system: Add option to maintain a supervision tree J. Neuschäfer via buildroot
@ 2024-07-14 21:11 ` Arnout Vandecappelle via buildroot
  2024-07-18 20:53   ` J. Neuschäfer via buildroot
  2024-07-14 22:12 ` Arnout Vandecappelle via buildroot
  1 sibling, 1 reply; 4+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2024-07-14 21:11 UTC (permalink / raw)
  To: J. Neuschäfer, buildroot

  Hi J.,

On 04/07/2024 21:00, J. Neuschäfer via buildroot wrote:
> 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.

  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

> 
> 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.
> 
> Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
> ---
>   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(+)
> 
> diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> index eb5e7ad922..31231bfc92 100644
> --- a/package/busybox/busybox.mk
> +++ b/package/busybox/busybox.mk
> @@ -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)
> diff --git a/package/busybox/inittab b/package/busybox/inittab
> index f2b4df801b..8bed294019 100644
> --- a/package/busybox/inittab
> +++ b/package/busybox/inittab
> @@ -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
> 
> diff --git a/package/sysvinit/inittab b/package/sysvinit/inittab
> index afc28e6c03..e70684fade 100644
> --- a/package/sysvinit/inittab
> +++ b/package/sysvinit/inittab
> @@ -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
> 
> diff --git a/package/sysvinit/sysvinit.mk b/package/sysvinit/sysvinit.mk
> index 7f37cea131..16509dd622 100644
> --- a/package/sysvinit/sysvinit.mk
> +++ b/package/sysvinit/sysvinit.mk
> @@ -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))
> diff --git a/system/Config.in b/system/Config.in
> index 3fb17ed1c6..bb88f276ec 100644
> --- a/system/Config.in
> +++ b/system/Config.in
> @@ -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 <j.neuschaefer@gmx.net>
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] system: Add option to maintain a supervision tree
  2024-07-04 19:00 [Buildroot] [PATCH] system: Add option to maintain a supervision tree J. Neuschäfer via buildroot
  2024-07-14 21:11 ` Arnout Vandecappelle via buildroot
@ 2024-07-14 22:12 ` Arnout Vandecappelle via buildroot
  1 sibling, 0 replies; 4+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2024-07-14 22:12 UTC (permalink / raw)
  To: J. Neuschäfer, buildroot



On 04/07/2024 21:00, J. Neuschäfer via buildroot wrote:
> 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.
> 
> Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>

  Applied to master, thanks.

  Regards,
  Arnout

> ---
>   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(+)
> 
> diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> index eb5e7ad922..31231bfc92 100644
> --- a/package/busybox/busybox.mk
> +++ b/package/busybox/busybox.mk
> @@ -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)
> diff --git a/package/busybox/inittab b/package/busybox/inittab
> index f2b4df801b..8bed294019 100644
> --- a/package/busybox/inittab
> +++ b/package/busybox/inittab
> @@ -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
> 
> diff --git a/package/sysvinit/inittab b/package/sysvinit/inittab
> index afc28e6c03..e70684fade 100644
> --- a/package/sysvinit/inittab
> +++ b/package/sysvinit/inittab
> @@ -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
> 
> diff --git a/package/sysvinit/sysvinit.mk b/package/sysvinit/sysvinit.mk
> index 7f37cea131..16509dd622 100644
> --- a/package/sysvinit/sysvinit.mk
> +++ b/package/sysvinit/sysvinit.mk
> @@ -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))
> diff --git a/system/Config.in b/system/Config.in
> index 3fb17ed1c6..bb88f276ec 100644
> --- a/system/Config.in
> +++ b/system/Config.in
> @@ -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 <j.neuschaefer@gmx.net>
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] system: Add option to maintain a supervision tree
  2024-07-14 21:11 ` Arnout Vandecappelle via buildroot
@ 2024-07-18 20:53   ` J. Neuschäfer via buildroot
  0 siblings, 0 replies; 4+ messages in thread
From: J. Neuschäfer via buildroot @ 2024-07-18 20:53 UTC (permalink / raw)
  To: Arnout Vandecappelle; +Cc: J. Neuschäfer, buildroot

On Sun, Jul 14, 2024 at 11:11:57PM +0200, Arnout Vandecappelle wrote:
>  Hi J.,
>
> On 04/07/2024 21:00, J. Neuschäfer via buildroot wrote:
> > 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.
>
>  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.

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.

>
>  Regardless, thank you for your contributions!

Again, thank you for your thoughtful and friendly reviews :)


-- jn
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2024-07-18 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-04 19:00 [Buildroot] [PATCH] system: Add option to maintain a supervision tree J. Neuschäfer via buildroot
2024-07-14 21:11 ` Arnout Vandecappelle via buildroot
2024-07-18 20:53   ` J. Neuschäfer via buildroot
2024-07-14 22:12 ` Arnout Vandecappelle via buildroot

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