commit:     13744710e120a8bbdea432ec1fb82f13ecc66a22
Author:     Z. Liu <zhixu.liu <AT> gmail <DOT> com>
AuthorDate: Wed Dec 18 03:37:24 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Dec 27 15:11:19 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=13744710

sys-process/runit: remove dependency on openrc

runit can be used either as a replacement of init (pid 1) or as a process
supervisor. We're discussing the first case here. Currently, Gentoo use openrc
to handle service startup and stop in runit's stage 1 & 3, which might be too
heavy for a lighweight init. Most people who choose runit as init will likely
to write their own scripts. Therefore, the call of openrc is changed to a
template script, and won't be called by default.

Additionally, to provide users with more options, a new USE "scripts" is added.
If disabled, no script(s) will be installed into /etc/runit.

1. remove dependency on openrc, add USE scripts (enabled by default), if
   disabled, will keep /etc/runit clean.
2. replace /bin/sh w/ /bin/bash for stage 1 & 3 scripts.
3. add /etc/runit/rc.sh to call user-defined scripts during stage 1 & 3
4. move the call of openrc in /etc/runit/{1,3} to 
/etc/runit/rc/{1,3}.openrc.example

Closes: https://bugs.gentoo.org/611846
Reviewed-by: Alex Efros <powerman-asdf <AT> yandex.ru>
Signed-off-by: Z. Liu <zhixu.liu <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/39776
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-process/runit/files/{1-2.1.2 => 1-r1}          |  0
 sys-process/runit/files/{1-2.1.2 => 1-r2}          |  7 ++--
 sys-process/runit/files/1.openrc.example           |  6 +++
 sys-process/runit/files/{2-2.1.2 => 2-r1}          |  0
 sys-process/runit/files/{3-2.1.2 => 3-r1}          |  0
 sys-process/runit/files/{3-2.1.2 => 3-r2}          |  9 +++--
 sys-process/runit/files/3.openrc.example           |  7 ++++
 sys-process/runit/files/rc.sh                      | 16 ++++++++
 .../runit/files/{run.getty-2.1.2 => run.getty}     |  0
 sys-process/runit/metadata.xml                     |  3 ++
 sys-process/runit/runit-2.1.2-r6.ebuild            |  8 ++--
 ...runit-2.1.2-r6.ebuild => runit-2.1.2-r7.ebuild} | 44 ++++++++++++++--------
 .../{runit-2.2.0.ebuild => runit-2.2.0-r1.ebuild}  | 44 ++++++++++++++--------
 13 files changed, 102 insertions(+), 42 deletions(-)

diff --git a/sys-process/runit/files/1-2.1.2 b/sys-process/runit/files/1-r1
similarity index 100%
copy from sys-process/runit/files/1-2.1.2
copy to sys-process/runit/files/1-r1

diff --git a/sys-process/runit/files/1-2.1.2 b/sys-process/runit/files/1-r2
similarity index 61%
rename from sys-process/runit/files/1-2.1.2
rename to sys-process/runit/files/1-r2
index 9761472ac739..0ca4cc880e91 100644
--- a/sys-process/runit/files/1-2.1.2
+++ b/sys-process/runit/files/1-r2
@@ -1,10 +1,11 @@
-#!/bin/sh
+#!/bin/bash
 # system one time tasks
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
-RUNLEVEL=S /sbin/openrc sysinit
-RUNLEVEL=S /sbin/openrc boot
+. /etc/runit/rc.sh
+
+run_rc_stage 1
 
 touch /etc/runit/stopit
 chmod 0 /etc/runit/stopit

diff --git a/sys-process/runit/files/1.openrc.example 
b/sys-process/runit/files/1.openrc.example
new file mode 100644
index 000000000000..816c33d26372
--- /dev/null
+++ b/sys-process/runit/files/1.openrc.example
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# example script in stage 1 using openrc, sys-apps/openrc must be installed
+
+RUNLEVEL=S /sbin/openrc sysinit
+RUNLEVEL=S /sbin/openrc boot

diff --git a/sys-process/runit/files/2-2.1.2 b/sys-process/runit/files/2-r1
similarity index 100%
rename from sys-process/runit/files/2-2.1.2
rename to sys-process/runit/files/2-r1

diff --git a/sys-process/runit/files/3-2.1.2 b/sys-process/runit/files/3-r1
similarity index 100%
copy from sys-process/runit/files/3-2.1.2
copy to sys-process/runit/files/3-r1

diff --git a/sys-process/runit/files/3-2.1.2 b/sys-process/runit/files/3-r2
similarity index 62%
rename from sys-process/runit/files/3-2.1.2
rename to sys-process/runit/files/3-r2
index 30e602cdae96..0b757c01fe22 100644
--- a/sys-process/runit/files/3-2.1.2
+++ b/sys-process/runit/files/3-r2
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 exec >/dev/console 2>&1
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
@@ -9,6 +9,7 @@ echo 'Waiting for services to stop...'
 sv -w 300 force-shutdown /etc/service/*
 
 echo 'Shutdown...'
-test -x /etc/runit/reboot && LAST=6    || LAST=0
-test -x /etc/runit/reboot && RC=reboot || RC=shutdown
-RUNLEVEL=$LAST /sbin/openrc $RC
+
+. /etc/runit/rc.sh
+
+run_rc_stage 3

diff --git a/sys-process/runit/files/3.openrc.example 
b/sys-process/runit/files/3.openrc.example
new file mode 100644
index 000000000000..2e4cb44f08ef
--- /dev/null
+++ b/sys-process/runit/files/3.openrc.example
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# example script in stage 3 using openrc, sys-apps/openrc must be installed
+
+test -x /etc/runit/reboot && LAST=6    || LAST=0
+test -x /etc/runit/reboot && RC=reboot || RC=shutdown
+RUNLEVEL=$LAST /sbin/openrc $RC

diff --git a/sys-process/runit/files/rc.sh b/sys-process/runit/files/rc.sh
new file mode 100644
index 000000000000..6e382ff9b712
--- /dev/null
+++ b/sys-process/runit/files/rc.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# run script(s) at /etc/runit/rc/, suffix must be .sh, prefix
+# must be [1|3] which denote stage 1 or 3.
+run_rc_stage() {
+       local prefix="${1}"
+       local prev_opt=$(shopt -p nullglob)
+       shopt -s nullglob
+       for file in /etc/runit/rc/"${prefix}".*.sh; do
+               if [[ ! -x "${file}" ]] || [[ ! -s "${file}" ]] ; then
+                       continue
+               fi
+               . "${file}"
+       done
+       ${prev_opt}
+}

diff --git a/sys-process/runit/files/run.getty-2.1.2 
b/sys-process/runit/files/run.getty
similarity index 100%
rename from sys-process/runit/files/run.getty-2.1.2
rename to sys-process/runit/files/run.getty

diff --git a/sys-process/runit/metadata.xml b/sys-process/runit/metadata.xml
index 73e765e89483..b959aa013a8b 100644
--- a/sys-process/runit/metadata.xml
+++ b/sys-process/runit/metadata.xml
@@ -12,4 +12,7 @@
   <upstream>
     <remote-id type="github">clan/runit</remote-id>
   </upstream>
+  <use>
+    <flag name="scripts">Install boot scripts into /etc/runit/.</flag>
+  </use>
 </pkgmetadata>

diff --git a/sys-process/runit/runit-2.1.2-r6.ebuild 
b/sys-process/runit/runit-2.1.2-r6.ebuild
index 3cc37408a6ee..2e67b0119a0d 100644
--- a/sys-process/runit/runit-2.1.2-r6.ebuild
+++ b/sys-process/runit/runit-2.1.2-r6.ebuild
@@ -69,15 +69,15 @@ src_install() {
 
        exeinto /etc/runit
        doexe "${FILESDIR}"/ctrlaltdel
-       newexe "${FILESDIR}"/1-${PV} 1
-       newexe "${FILESDIR}"/2-${PV} 2
-       newexe "${FILESDIR}"/3-${PV} 3
+       newexe "${FILESDIR}"/1-r1 1
+       newexe "${FILESDIR}"/2-r1 2
+       newexe "${FILESDIR}"/3-r1 3
 
        dodir /etc/sv
        for tty in tty1 tty2 tty3 tty4 tty5 tty6; do
                exeinto /etc/sv/getty-$tty/
                newexe "${FILESDIR}"/finish.getty finish
-               newexe "${FILESDIR}"/run.getty-${PV} run
+               newexe "${FILESDIR}"/run.getty run
                for script in finish run; do
                        sed -i -e "s:TTY:${tty}:g" 
"${ED}"/etc/sv/getty-$tty/$script
                done

diff --git a/sys-process/runit/runit-2.1.2-r6.ebuild 
b/sys-process/runit/runit-2.1.2-r7.ebuild
similarity index 76%
copy from sys-process/runit/runit-2.1.2-r6.ebuild
copy to sys-process/runit/runit-2.1.2-r7.ebuild
index 3cc37408a6ee..1ef4c5e2877d 100644
--- a/sys-process/runit/runit-2.1.2-r6.ebuild
+++ b/sys-process/runit/runit-2.1.2-r7.ebuild
@@ -16,10 +16,8 @@ S=${WORKDIR}/admin/${P}/src
 
 LICENSE="BSD"
 SLOT="0"
-KEYWORDS="~alpha amd64 arm arm64 ~hppa ~m68k ~mips ppc ppc64 ~s390 sparc x86"
-IUSE="split-usr static"
-
-RDEPEND="sys-apps/openrc"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~m68k ~mips ~ppc ~ppc64 ~s390 ~sparc 
~x86"
+IUSE="+scripts split-usr static"
 
 src_unpack() {
        unpack ${P}.tar.gz
@@ -67,17 +65,23 @@ src_install() {
        einstalldocs
        doman ../man/*.[18]
 
-       exeinto /etc/runit
-       doexe "${FILESDIR}"/ctrlaltdel
-       newexe "${FILESDIR}"/1-${PV} 1
-       newexe "${FILESDIR}"/2-${PV} 2
-       newexe "${FILESDIR}"/3-${PV} 3
+       if use scripts ; then
+               exeinto /etc/runit
+               doexe "${FILESDIR}"/ctrlaltdel
+               newexe "${FILESDIR}"/1-r2 1
+               newexe "${FILESDIR}"/2-r1 2
+               newexe "${FILESDIR}"/3-r2 3
+               doexe "${FILESDIR}"/rc.sh
+               insinto /etc/runit/rc
+               doins "${FILESDIR}"/1.openrc.example
+               doins "${FILESDIR}"/3.openrc.example
+       fi
 
        dodir /etc/sv
        for tty in tty1 tty2 tty3 tty4 tty5 tty6; do
                exeinto /etc/sv/getty-$tty/
                newexe "${FILESDIR}"/finish.getty finish
-               newexe "${FILESDIR}"/run.getty-${PV} run
+               newexe "${FILESDIR}"/run.getty run
                for script in finish run; do
                        sed -i -e "s:TTY:${tty}:g" 
"${ED}"/etc/sv/getty-$tty/$script
                done
@@ -129,11 +133,21 @@ pkg_postinst() {
                migrate_from_211
        fi
 
-       ewarn "To make sure sv works correctly in your currently open"
-       ewarn "shells, please run the following command:"
-       ewarn
-       ewarn "source /etc/profile"
-       ewarn
+       if use scripts; then
+               ewarn "To make sure sv works correctly in your currently open"
+               ewarn "shells, please run the following command:"
+               ewarn
+               ewarn "source /etc/profile"
+               ewarn
+               ewarn "Currently, no task(s) will run in stage 1 & 3, you're on 
your own"
+               ewarn "to put script(s) into /etc/runit/rc/, please see 
/etc/runit/rc.sh"
+               ewarn "for name in different stages."
+       else
+               ewarn "This build with USE=\"-scripts\" doesn\'t include any 
boot scripts"
+               ewarn "into /etc/runit, you are on your own to put the scripts."
+               ewarn "Also, /sbin/runsvdir-start is a broken symlink to 
/etc/runit/2, you will"
+               ewarn "need to create script /etc/runit/2 before use it."
+       fi
 
        if [[ -L "${EROOT}"/var/service ]]; then
                ewarn "Once this version of runit is active, please remove the"

diff --git a/sys-process/runit/runit-2.2.0.ebuild 
b/sys-process/runit/runit-2.2.0-r1.ebuild
similarity index 76%
rename from sys-process/runit/runit-2.2.0.ebuild
rename to sys-process/runit/runit-2.2.0-r1.ebuild
index 5f369e745738..5a77acc25416 100644
--- a/sys-process/runit/runit-2.2.0.ebuild
+++ b/sys-process/runit/runit-2.2.0-r1.ebuild
@@ -16,9 +16,7 @@ S=${WORKDIR}/admin/${P}/src
 LICENSE="BSD"
 SLOT="0"
 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~m68k ~mips ~ppc ~ppc64 ~s390 ~sparc 
~x86"
-IUSE="split-usr static"
-
-RDEPEND="sys-apps/openrc"
+IUSE="+scripts split-usr static"
 
 src_prepare() {
        default
@@ -45,8 +43,6 @@ src_configure() {
 }
 
 src_install() {
-       local ver_runit_cfg="2.1.2"  # use files from 2.1.2
-
        dobin $(<../package/commands)
        dodir /sbin
        mv "${ED}"/usr/bin/{runit-init,runit,utmpset} "${ED}"/sbin/ || die 
"dosbin"
@@ -61,17 +57,23 @@ src_install() {
        einstalldocs
        doman ../man/*.[18]
 
-       exeinto /etc/runit
-       doexe "${FILESDIR}"/ctrlaltdel
-       newexe "${FILESDIR}"/1-${ver_runit_cfg} 1
-       newexe "${FILESDIR}"/2-${ver_runit_cfg} 2
-       newexe "${FILESDIR}"/3-${ver_runit_cfg} 3
+       if use scripts ; then
+               exeinto /etc/runit
+               doexe "${FILESDIR}"/ctrlaltdel
+               newexe "${FILESDIR}"/1-r2 1
+               newexe "${FILESDIR}"/2-r1 2
+               newexe "${FILESDIR}"/3-r2 3
+               doexe "${FILESDIR}"/rc.sh
+               insinto /etc/runit/rc
+               doins "${FILESDIR}"/1.openrc.example
+               doins "${FILESDIR}"/3.openrc.example
+       fi
 
        dodir /etc/sv
        for tty in tty1 tty2 tty3 tty4 tty5 tty6; do
                exeinto /etc/sv/getty-$tty/
                newexe "${FILESDIR}"/finish.getty finish
-               newexe "${FILESDIR}"/run.getty-${ver_runit_cfg} run
+               newexe "${FILESDIR}"/run.getty run
                for script in finish run; do
                        sed -i -e "s:TTY:${tty}:g" 
"${ED}"/etc/sv/getty-$tty/$script
                done
@@ -123,11 +125,21 @@ pkg_postinst() {
                migrate_from_211
        fi
 
-       ewarn "To make sure sv works correctly in your currently open"
-       ewarn "shells, please run the following command:"
-       ewarn
-       ewarn "source /etc/profile"
-       ewarn
+       if use scripts; then
+               ewarn "To make sure sv works correctly in your currently open"
+               ewarn "shells, please run the following command:"
+               ewarn
+               ewarn "source /etc/profile"
+               ewarn
+               ewarn "Currently, no task(s) will run in stage 1 & 3, you're on 
your own"
+               ewarn "to put script(s) into /etc/runit/rc/, please see 
/etc/runit/rc.sh"
+               ewarn "for name in different stages."
+       else
+               ewarn "This build with USE=\"-scripts\" doesn\'t include any 
boot scripts"
+               ewarn "into /etc/runit, you are on your own to put the scripts."
+               ewarn "Also, /sbin/runsvdir-start is a broken symlink to 
/etc/runit/2, you will"
+               ewarn "need to create script /etc/runit/2 before use it."
+       fi
 
        if [[ -L "${EROOT}"/var/service ]]; then
                ewarn "Once this version of runit is active, please remove the"

Reply via email to