Skip to contentSkip to conversation

init: Add s6 as init system

RFC New Vadim Kochan 3 participants 8 messages Jan 16, 2019 – Feb 11, 2019

lore
Share & tools
lore
#0 lore raw

cover init: Add s6 as init system

Add new system init support (BR2_INIT_S6) based on s6 suite. This is very-very basic support which does not have any setup automation logic (but only getty) but it allows to install custom s6-rc services in a bit easier way by the board. All s6-rc services which were copied by rootfs-overlay or post-build will be compiled as s6-rc db into /etc/s6-rc/compiled-initial, which also has /etc/s6-rc/compiled link to easy replace it in runtime.

In case if such kind of change will be merged, then may be it would be good to think about of some packages integration into s6-rc system.

Vadim Kochan (3):
package/s6-linux-init: Build also for the host package/s6-linux-init: Allow to install as init system package/s6-rc: Allow to integrate s6-rc services

 package/s6-linux-init/s6-linux-init.mk | 69 +++++++++++++++++++++++++++++++++-
 package/s6-rc/rc.init                  |  4 ++
 package/s6-rc/rc.shutdown              |  3 ++
 package/s6-rc/s6-rc.mk                 | 32 ++++++++++++++++
 system/Config.in                       |  9 ++++-
 5 files changed, 114 insertions(+), 3 deletions(-)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
Signature · 1 line
2.14.1
#1 lore raw

RFC 1/3 package/s6-linux-init: Build also for the host

Add strict dependency for host-s6-linux-init to use s6-linux-init-maker on the host during the rootfs generation.

---
 package/s6-linux-init/s6-linux-init.mk | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
package/s6-linux-init/s6-linux-init.mk +28 -1
index d25504ae5a..913f837c1f 100644
@@ -8,7 +8,7 @@ S6_LINUX_INIT_VERSION = 0.4.0.0
 S6_LINUX_INIT_SITE = http://skarnet.org/software/s6-linux-init
 S6_LINUX_INIT_LICENSE = ISC
 S6_LINUX_INIT_LICENSE_FILES = COPYING
-S6_LINUX_INIT_DEPENDENCIES = s6 s6-linux-utils s6-portable-utils
+S6_LINUX_INIT_DEPENDENCIES = s6 s6-linux-utils s6-portable-utils host-s6-linux-init
 
 S6_LINUX_INIT_CONF_OPTS = \
 	--prefix=/usr \
@@ -33,4 +33,31 @@ define S6_LINUX_INIT_INSTALL_TARGET_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) install
 endef
 
+HOST_S6_LINUX_INIT_DEPENDENCIES = host-s6
+
+HOST_S6_LINUX_INIT_CONF_OPTS = \
+	--prefix=$(HOST_DIR) \
+	--with-sysdeps=$(HOST_DIR)/usr/lib/skalibs/sysdeps \
+	--with-include=$(HOST_DIR)/usr/include \
+	--with-dynlib=$(HOST_DIR)/usr/lib \
+	--with-lib=$(HOST_DIR)/usr/lib/execline \
+	--with-lib=$(HOST_DIR)/usr/lib/s6 \
+	--with-lib=$(HOST_DIR)/usr/lib/skalibs \
+	--disable-static \
+	--enable-shared \
+	--disable-allstatic
+
+define HOST_S6_LINUX_INIT_CONFIGURE_CMDS
+	(cd $(@D); $(HOST_CONFIGURE_OPTS) ./configure $(HOST_S6_LINUX_INIT_CONF_OPTS))
+endef
+
+define HOST_S6_LINUX_INIT_BUILD_CMDS
+	$(HOST_MAKE_ENV) $(MAKE) -C $(@D)
+endef
+
+define HOST_S6_LINUX_INIT_INSTALL_CMDS
+	$(HOST_MAKE_ENV) $(MAKE) -C $(@D) install
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))
Signature · 1 line
2.14.1
#2 lore raw

RFC 2/3 package/s6-linux-init: Allow to install as init system

In reply to Vadim Kochan

Add BR2_INIT_S6 option which allows to install minimal init support by s6-linux-init-maker into /etc/s6 and link /sbin/init to it.

Also 2 additional files /etc/rc.init and /etc/rc.shutdown are generated as dummy "execline'd" scripts which are triggered by /etc/s6/init.

Consider generic tty option support and generate getty service if needed by s6-linux-init-maker.

---
 package/s6-linux-init/s6-linux-init.mk | 40 ++++++++++++++++++++++++++++++++++
 system/Config.in                       |  9 ++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)
package/s6-linux-init/s6-linux-init.mk +40 -0
index 913f837c1f..c298d62477 100644
@@ -33,6 +33,46 @@ define S6_LINUX_INIT_INSTALL_TARGET_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) install
 endef
 
+ifeq ($(BR2_INIT_S6),y)
+
+# Don't let Busybox to install it's own tools like poweroff, reboot, halt, etc
+S6_LINUX_INIT_DEPENDENCIES += $(if $(BR2_PACKAGE_BUSYBOX),busybox)
+
+S6_LINUX_INIT_MAKER_OPTS = -b /usr/bin -c /etc/s6
+
+ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
+S6_LINUX_INIT_MAKER_OPTS += -d 0
+else
+S6_LINUX_INIT_MAKER_OPTS += $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_DEVTMPFS),,-d 1)
+endif
+
+ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
+S6_LINUX_INIT_MAKER_OPTS += -G "/sbin/getty -L \
+			  $(SYSTEM_GETTY_OPTIONS) \
+			  $(SYSTEM_GETTY_PORT) \
+			  $(SYSTEM_GETTY_BAUDRATE) \
+			  $(SYSTEM_GETTY_TERM)"
+endif
+
+define S6_LINUX_INIT_INSTALL_INIT
+	ln -sf ../etc/s6/init $(TARGET_DIR)/sbin/init
+
+	ln -sf /usr/bin/s6-reboot $(TARGET_DIR)/sbin/reboot
+	ln -sf /usr/bin/s6-poweroff $(TARGET_DIR)/sbin/poweroff
+	ln -sf /usr/bin/s6-halt $(TARGET_DIR)/sbin/halt
+
+	echo "#! /usr/bin/execlineb -P" > $(@D)/rc.init
+	$(INSTALL) -m 0755 $(@D)/rc.init $(TARGET_DIR)/etc/rc.init
+	echo "#! /usr/bin/execlineb -P" > $(@D)/rc.shutdown
+	$(INSTALL) -m 0755 $(@D)/rc.shutdown $(TARGET_DIR)/etc/rc.shutdown
+
+	rm -rf $(TARGET_DIR)/etc/s6
+	$(HOST_DIR)/bin/s6-linux-init-maker $(S6_LINUX_INIT_MAKER_OPTS) $(TARGET_DIR)/etc/s6
+endef
+S6_LINUX_INIT_POST_INSTALL_TARGET_HOOKS += S6_LINUX_INIT_INSTALL_INIT
+
+endif # BR2_INIT_S6
+
 HOST_S6_LINUX_INIT_DEPENDENCIES = host-s6
 
 HOST_S6_LINUX_INIT_CONF_OPTS = \
system/Config.in +7 -2
index 9941807e5d..5bab283931 100644
@@ -12,6 +12,7 @@ config BR2_ROOTFS_SKELETON_DEFAULT
 	select BR2_PACKAGE_SKELETON_INIT_SYSV if BR2_INIT_SYSV
 	select BR2_PACKAGE_SKELETON_INIT_SYSV if BR2_INIT_BUSYBOX
 	select BR2_PACKAGE_SKELETON_INIT_SYSTEMD if BR2_INIT_SYSTEMD
+	select BR2_PACKAGE_SKELETON_INIT_COMMON if BR2_INIT_S6
 	select BR2_PACKAGE_SKELETON_INIT_NONE if BR2_INIT_NONE
 	help
 	  Use default target skeleton
@@ -124,6 +125,10 @@ comment "systemd needs a glibc toolchain w/ SSP, headers >= 3.10"
 		!BR2_TOOLCHAIN_HAS_SSP || \
 		!BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_10
 
+config BR2_INIT_S6
+	bool "s6"
+	select BR2_PACKAGE_S6_LINUX_INIT
+
 config BR2_INIT_NONE
 	bool "None"
 	help
@@ -342,7 +347,7 @@ config BR2_TARGET_GENERIC_GETTY_TERM
 	string "TERM environment variable"
 	default "vt100"
 	# currently observed only by busybox and sysvinit
-	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV
+	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV || BR2_INIT_S6
 	help
 	  Specify a TERM type.
 
@@ -350,7 +355,7 @@ config BR2_TARGET_GENERIC_GETTY_OPTIONS
 	string "other options to pass to getty"
 	default ""
 	# currently observed only by busybox and sysvinit
-	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV
+	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV || BR2_INIT_S6
 	help
 	  Any other flags you want to pass to getty,
 	  Refer to getty --help for details.
Signature · 1 line
2.14.1
#3 lore raw

RFC 3/3 package/s6-rc: Allow to integrate s6-rc services

In reply to Vadim Kochan

It allows to install s6-rc services by board or package into /etc/s6-rc/service which will be compiled as s6-rc db as /etc/s6-rc/compiled-initial. Services are compiled on stage when rootfs overlay & post-build already performed.

Added rc.init & rc.shutdown scripts which are needed to run s6-rc services.

This is very basic s6-rc system support which even does not have the basic stuff like /proc /sys /dev setup, but this might be added in future work.

All above is only possible if BR2_INIT_S6 is selected.

---
 package/s6-rc/rc.init     |  4 ++++
 package/s6-rc/rc.shutdown |  3 +++
 package/s6-rc/s6-rc.mk    | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
package/s6-rc/rc.init new file +4 -0
new file mode 100644
index 0000000000..6709c6488b
@@ -0,0 +1,4 @@
+#! /usr/bin/execlineb -P
+
+if { s6-rc-init /run/service }
+if { s6-rc -t 600000 -- change default }
package/s6-rc/rc.shutdown new file +3 -0
new file mode 100644
index 0000000000..58d49b5cfd
@@ -0,0 +1,3 @@
+#! /usr/bin/execlineb -P
+
+s6-rc -da change
package/s6-rc/s6-rc.mk +32 -0
index 222ba139c6..007e7d9e1b 100644
@@ -11,6 +11,13 @@ S6_RC_LICENSE_FILES = COPYING
 S6_RC_INSTALL_STAGING = YES
 S6_RC_DEPENDENCIES = s6
 
+ifeq ($(BR2_INIT_S6),y)
+# Needs s6-rc-compile to create initial rc db, also
+# build after s6-linux-init to rewrite rc.init for run
+# s6-rc services.
+S6_RC_DEPENDENCIES += host-s6-rc s6-linux-init
+endif
+
 S6_RC_CONF_OPTS = \
 	--prefix=/usr \
 	--with-sysdeps=$(STAGING_DIR)/usr/lib/skalibs/sysdeps \
@@ -44,6 +51,31 @@ define S6_RC_INSTALL_STAGING_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(STAGING_DIR) install
 endef
 
+ifeq ($(BR2_INIT_S6),y)
+
+define S6_RC_PREPARE_INIT_RC
+	mkdir -p $(TARGET_DIR)/etc/s6-rc/service/default
+	echo bundle > $(TARGET_DIR)/etc/s6-rc/service/default/type
+	touch $(TARGET_DIR)/etc/s6-rc/service/default/contents
+
+	mkdir -p $(TARGET_DIR)/etc/s6-rc/compiled-initial
+	ln -sf compiled-initial $(TARGET_DIR)/etc/s6-rc/compiled
+
+	$(INSTALL) -m 0755 $(S6_RC_PKGDIR)/rc.init $(TARGET_DIR)/etc/rc.init
+	$(INSTALL) -m 0755 $(S6_RC_PKGDIR)/rc.shutdown $(TARGET_DIR)/etc/rc.shutdown
+endef
+S6_RC_POST_INSTALL_TARGET_HOOKS += S6_RC_PREPARE_INIT_RC
+
+define S6_RC_FINALIZE_INIT_RC
+	rm -rf $(TARGET_DIR)/etc/s6-rc/compiled-initial
+	$(HOST_DIR)/bin/s6-rc-compile -v 1 \
+		$(TARGET_DIR)/etc/s6-rc/compiled-initial \
+		$(TARGET_DIR)/etc/s6-rc/service
+endef
+S6_RC_ROOTFS_PRE_CMD_HOOKS += S6_RC_FINALIZE_INIT_RC
+
+endif # BR2_INIT_S6
+
 HOST_S6_RC_DEPENDENCIES = host-s6
 
 HOST_S6_RC_CONF_OPTS = \
Signature · 1 line
2.14.1
#4 lore raw

cover init: Add s6 as init system

In reply to Vadim Kochan

Hi!

Quoted 24 lines · Vadim Kochan

Add new system init support (BR2_INIT_S6) based on s6 suite. This is very-very basic support which does not have any setup automation logic (but only getty) but it allows to install custom s6-rc services in a bit easier way by the board. All s6-rc services which were copied by rootfs-overlay or post-build will be compiled as s6-rc db into /etc/s6-rc/compiled-initial, which also has /etc/s6-rc/compiled link to easy replace it in runtime.

In case if such kind of change will be merged, then may be it would be good to think about of some packages integration into s6-rc system.

Vadim Kochan (3):
package/s6-linux-init: Build also for the host package/s6-linux-init: Allow to install as init system package/s6-rc: Allow to integrate s6-rc services

 package/s6-linux-init/s6-linux-init.mk | 69 +++++++++++++++++++++++++++++++++-
 package/s6-rc/rc.init                  |  4 ++
 package/s6-rc/rc.shutdown              |  3 ++
 package/s6-rc/s6-rc.mk                 | 32 ++++++++++++++++
 system/Config.in                       |  9 ++++-
 5 files changed, 114 insertions(+), 3 deletions(-)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
Quoted 3 lines

--
2.14.1

I worked on a s6-based init system eons ago [1], but without using a host variant of s6-linux-init.

I'll test your patches.

[1] https://github.com/elebihan/br2-ext-skarnet

Regards,

--
ELB

#5 lore raw

cover init: Add s6 as init system

Hi Eric, Vadim,

El dom., 20 ene. 2019 a las 16:32, Eric Le Bihan
(<[email protected]>) escribi?:

Quoted 31 lines

Hi!

Quoted 24 lines · Vadim Kochan

Add new system init support (BR2_INIT_S6) based on s6 suite. This is very-very basic support which does not have any setup automation logic (but only getty) but it allows to install custom s6-rc services in a bit easier way by the board. All s6-rc services which were copied by rootfs-overlay or post-build will be compiled as s6-rc db into /etc/s6-rc/compiled-initial, which also has /etc/s6-rc/compiled link to easy replace it in runtime.

In case if such kind of change will be merged, then may be it would be good to think about of some packages integration into s6-rc system.

Vadim Kochan (3):
package/s6-linux-init: Build also for the host package/s6-linux-init: Allow to install as init system package/s6-rc: Allow to integrate s6-rc services

 package/s6-linux-init/s6-linux-init.mk | 69 +++++++++++++++++++++++++++++++++-
 package/s6-rc/rc.init                  |  4 ++
 package/s6-rc/rc.shutdown              |  3 ++
 package/s6-rc/s6-rc.mk                 | 32 ++++++++++++++++
 system/Config.in                       |  9 ++++-
 5 files changed, 114 insertions(+), 3 deletions(-)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
Quoted 3 lines

--
2.14.1

Quoted 7 lines

I worked on a s6-based init system eons ago [1], but without using a host variant of s6-linux-init.

I'll test your patches.

[1] https://github.com/elebihan/br2-ext-skarnet

We are based on Eric's original s6 init files, before it was moved to a BR2_EXTERNAL logic.
But I'm no s6 expert at all, so I can't really comment on these changes. Nevertheless, I'm quite interested to see how this evolves so we can align our local situation with something in upstream Buildroot.

Best regards,
Thomas

#6 lore raw

cover init: Add s6 as init system

In reply to Eric Le Bihan

Hi Eric,

Quoted 33 lines · Eric Le Bihan

Hi!

Quoted 24 lines · Vadim Kochan

Add new system init support (BR2_INIT_S6) based on s6 suite. This is very-very basic support which does not have any setup automation logic (but only getty) but it allows to install custom s6-rc services in a bit easier way by the board. All s6-rc services which were copied by rootfs-overlay or post-build will be compiled as s6-rc db into /etc/s6-rc/compiled-initial, which also has /etc/s6-rc/compiled link to easy replace it in runtime.

In case if such kind of change will be merged, then may be it would be good to think about of some packages integration into s6-rc system.

Vadim Kochan (3):
package/s6-linux-init: Build also for the host package/s6-linux-init: Allow to install as init system package/s6-rc: Allow to integrate s6-rc services

 package/s6-linux-init/s6-linux-init.mk | 69 +++++++++++++++++++++++++++++++++-
 package/s6-rc/rc.init                  |  4 ++
 package/s6-rc/rc.shutdown              |  3 ++
 package/s6-rc/s6-rc.mk                 | 32 ++++++++++++++++
 system/Config.in                       |  9 ++++-
 5 files changed, 114 insertions(+), 3 deletions(-)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
Quoted 3 lines

--
2.14.1

I worked on a s6-based init system eons ago [1], but without using a host variant of s6-linux-init.

Quoted 8 lines

I'll test your patches.

[1] https://github.com/elebihan/br2-ext-skarnet

Regards,

--
ELB

Do you have any conceptual comments regarding this ? Also I think may be it's better to have /etc/s6-rc into /etc/s6/rc.

Thanks!
Vadim Kochan

#7 lore raw

cover init: Add s6 as init system

Quoted 40 lines · Vadym Kochan

Hi Eric,

Quoted 37 lines · Eric Le Bihan

Hi!

Quoted 24 lines · Vadim Kochan

Add new system init support (BR2_INIT_S6) based on s6 suite. This is very-very basic support which does not have any setup automation logic (but only getty) but it allows to install custom s6-rc services in a bit easier way by the board. All s6-rc services which were copied by rootfs-overlay or post-build will be compiled as s6-rc db into /etc/s6-rc/compiled-initial, which also has /etc/s6-rc/compiled link to easy replace it in runtime.

In case if such kind of change will be merged, then may be it would be good to think about of some packages integration into s6-rc system.

Vadim Kochan (3):
package/s6-linux-init: Build also for the host package/s6-linux-init: Allow to install as init system package/s6-rc: Allow to integrate s6-rc services

 package/s6-linux-init/s6-linux-init.mk | 69 +++++++++++++++++++++++++++++++++-
 package/s6-rc/rc.init                  |  4 ++
 package/s6-rc/rc.shutdown              |  3 ++
 package/s6-rc/s6-rc.mk                 | 32 ++++++++++++++++
 system/Config.in                       |  9 ++++-
 5 files changed, 114 insertions(+), 3 deletions(-)
 create mode 100644 package/s6-rc/rc.init
 create mode 100644 package/s6-rc/rc.shutdown
Quoted 3 lines

--
2.14.1

I worked on a s6-based init system eons ago [1], but without using a host variant of s6-linux-init.

I'll test your patches.

[1] https://github.com/elebihan/br2-ext-skarnet

Quoted 7 lines
Quoted 4 lines

Regards,

--
ELB

Do you have any conceptual comments regarding this ? Also I think may be it's better to have /etc/s6-rc into /etc/s6/rc.

I tested your series and it works fine. As you are using the file system pre and post command hooks to compile the database services, this is cleaner than using a post-build script as done in my external customization.

I had not used s6-linux-init-maker at that time, but favored a hand-written init. Now this tool does the job, so it is OK to use it.

If this series is applied and a s6-based init option is available to the user, I think that providing kerneld/syslogd via s6-log may be useful. The same may apply to network configuration. The selling point of a s6-based init system is the service supervision and having the basic services available and supervised contribute to it.

But adding support for s6-compliant services is tricky, as unlike systemd, services are not available as files but as directories. So providing some for the basic services in Buildroot may clutter the source tree. My approach was to provide them via dedicated projects (s6-br2-init{skeleton,services}), but there may be a cleaner one. The nosh init system [1] provides a tool to convert systemd services, so may be such a tool for s6 may do the trick.

As for /etc/s6-rc vs. /etc/s6/rc, the later may indeed be better, as there is already /etc/s6/init.

[1] https://jdebp.eu/Softwares/nosh/

Regards,

--
ELB