View previous topic :: View next topic |
Author |
Message |
Alverstone n00b

Joined: 28 Apr 2025 Posts: 3
|
Posted: Mon Apr 28, 2025 9:49 am Post subject: Help alternative init systems |
|
|
A terrible lack (or my ignorance of otherwise) of openrc is that while you are able to simply invoke /bin/openrc to start runlevels, you can not actually use it to stop them, at least when openrc-init is not PID 1. As the result implementing shutdown sequence on alternative init systems is a feat of reading /etc/runlevels/{sysinit,boot} and manually deciding which of these services need stopping and in which order.
Rolling a new boot sequence for each init system is a competition of who makes more bugs, but inability to gracefully stop openrc runlevels makes it unfeasible to reuse openrc's boot sequence in a fully functional way. If this became possible, life for other init systems would become significantly easier.
– A runit user |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1656 Location: Richmond Hill, Canada
|
Posted: Mon Apr 28, 2025 12:18 pm Post subject: Re: Help alternative init systems |
|
|
Alverstone wrote: | A terrible lack (or my ignorance of otherwise) of openrc is that while you are able to simply invoke /bin/openrc to start runlevels, you can not actually use it to stop them, at least when openrc-init is not PID 1. | Can you use a example to explain what you mean. |
|
Back to top |
|
 |
GDH-gentoo Veteran


Joined: 20 Jul 2019 Posts: 1871 Location: South America
|
Posted: Mon Apr 28, 2025 12:30 pm Post subject: |
|
|
If distributions implement other init systems in a way that depends on the openrc binary and OpenRC service scripts, they are doing it wrong
— A user of an s6-based init system
EDIT:
Alverstone wrote: | – A runit user |
Now, the runit package in particular does not provide a service manager, so you might want to try using OpenRC on top of runit to provide that capability, kind of like it is used on top of sysvinit on Gentoo. In that case, the strategy would be to call the openrc program in /etc/runit/1, and then call it again as openrc shutdown in /etc/runit/3. That stops services started by other (OpenRC!) runlevels. However I don't know how well that would work in practice.
Runit on Void does not use OpenRC. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer  |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though  |
|
|
Back to top |
|
 |
Alverstone n00b

Joined: 28 Apr 2025 Posts: 3
|
Posted: Mon Apr 28, 2025 4:44 pm Post subject: Re: Help alternative init systems |
|
|
pingtoo wrote: | Can you use a example to explain what you mean. |
Consider the default /etc/runit/{1,3} implementation:
Code: |
#!/bin/bash
# system one time tasks
PATH=/sbin:/usr/sbin:/bin:/usr/bin
RUNLEVEL=S /sbin/openrc sysinit
RUNLEVEL=S /sbin/openrc boot
touch /etc/runit/stopit
chmod 0 /etc/runit/stopit
|
and
Code: |
#!/bin/bash
sv -w 300 force-shutdown /etc/service/*
. /etc/runit/rc.sh
run_rc_stage 3
|
The function run_rc_stage 3 is
Code: |
#!/bin/sh
test -x /etc/runit/reboot && LAST=6 || LAST=0
test -x /etc/runit/reboot && RC=reboot || RC=shutdown
RUNLEVEL=$LAST /sbin/openrc $RC
|
When the "/sbin/openrc shudown" or "/sbin/openrc reboot" executes, the boot and sysinit runlevels are not stopped. That needs to be manually implemented in context of rc-service, which is messy.
GDH-gentoo wrote: | If distributions implement other init systems in a way that depends on the openrc binary and OpenRC service scripts, they are doing it wrong
— A user of an s6-based init system |
Why is that so? Re-implementing the boot sequence is a mess, it is a blessing when some parts of it can be simply reused to avoid over saturating universe with wheels Openrc's boot sequence isn't entirely clean to reuse just yet.
Quote: | using OpenRC on top of runit to provide that capability, kind of like it is used on top of sysvinit on Gentoo |
I do use openrc to manage stages 1 and 3, though not exclusively. Rather, I build my own gimmicks on top of what openrc provides out of the box. For example, my /etc/runit/1 is simply
Code: |
#!/bin/bash
# system one time tasks
PATH=/sbin:/usr/sbin:/bin:/usr/bin
RUNLEVEL=S /sbin/openrc sysinit
/etc/runit/bootrc early
RUNLEVEL=S /sbin/openrc boot
/etc/runit/bootrc late
touch /etc/runit/stopit
touch /etc/runit/reboot
chmod 000 /etc/runit/stopit
chmod 000 /etc/runit/reboot
|
Quote: | Runit on Void does not use OpenRC. |
Void has incomplete boot sequence that only supports the default scenario and allows very little flexibility. Gentoo's openrc boot sequence is quite superior to Void's. Also, Void isn't relevant since the question is about gentoo. |
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2132
|
Posted: Mon Apr 28, 2025 5:27 pm Post subject: |
|
|
Alverstone wrote: | When the "/sbin/openrc shudown" or "/sbin/openrc reboot" executes, the boot and sysinit runlevels are not stopped. That needs to be manually implemented in context of rc-service, which is messy. |
The boot and sysinit runlevels are not meant to be stopped (including any services included therein). They exist for basic tools to bring a system to a nominal usable state with all of the services can be terminated by a hardware reboot/shutdown without recourse.
Any service that is able to be stopped must be in a runlevel besides those. (Fun fact, you can create custom runlevels but hardly anyone does.)
Edit: Reread last sentence and found issues with it. Fixed
Last edited by grknight on Mon Apr 28, 2025 8:19 pm; edited 1 time in total |
|
Back to top |
|
 |
GDH-gentoo Veteran


Joined: 20 Jul 2019 Posts: 1871 Location: South America
|
Posted: Mon Apr 28, 2025 5:49 pm Post subject: Re: Help alternative init systems |
|
|
Alverstone wrote: | GDH-gentoo wrote: | If distributions implement other init systems in a way that depends on the openrc binary and OpenRC service scripts, they are doing it wrong
— A user of an s6-based init system |
Why is that so? |
Because the mechanism used by OpenRC for implementing the boot sequence (and shutdown sequence) is... surprise! OpenRC-specific You wouldn't be using an alternative init system, you'd just have that init system delegate to OpenRC.
Which leads me to:
Alverstone wrote: | [...] some parts of it can be simply reused [...] |
Uh... no? Did you see the #!/sbin/openrc-run in the service scripts? It's like saying we could simply reuse systemd unit files.
Unless OpenRC is part of the init system, which is a different discussion.
What we can do is replicate the effect of OpenRC's service scripts in whatever format an alternative service manager, such as s6-rc, accepts. Harder to do for runit because, well, it hasn't any. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer  |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though  |
|
|
Back to top |
|
 |
Alverstone n00b

Joined: 28 Apr 2025 Posts: 3
|
Posted: Tue Apr 29, 2025 5:19 pm Post subject: |
|
|
grknight wrote: | Alverstone wrote: | When the "/sbin/openrc shudown" or "/sbin/openrc reboot" executes, the boot and sysinit runlevels are not stopped. That needs to be manually implemented in context of rc-service, which is messy. |
The boot and sysinit runlevels are not meant to be stopped (including any services included therein). They exist for basic tools to bring a system to a nominal usable state with all of the services can be terminated by a hardware reboot/shutdown without recourse.
Any service that is able to be stopped must be in a runlevel besides those. (Fun fact, you can create custom runlevels but hardly anyone does.)
Edit: Reread last sentence and found issues with it. Fixed |
What about /etc/init.d/hwclock?
I do not want to argue with any of what GDH-gentoo says, because he's not wrong. runit does not have any service management, so it has to rely on other tools (or on manually written scripts) to manage its boot and shutdown sequences. I'm not even talking about the suckless init. For reasons described above I can't reuse openrc without uncool tweaking. Unless grknight is right, of course. If boot and sysinit do not contain services that need stopping, then my initial point is irrelevant. However, I think grknight needs to elaborate, because some things in boot have stop() functions defined for them. Other examples beside hwclock are seedrng, swap and dmcrypt. The last two definitely need stopping. |
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2132
|
Posted: Tue Apr 29, 2025 5:30 pm Post subject: |
|
|
Alverstone wrote: | Other examples beside hwclock are seedrng, swap and dmcrypt. The last two definitely need stopping. |
No, the last two do not need stopping normally. If a system is rebooting or halting, then the kernel will clean up. dmcrypt is encrypted at rest without any action. |
|
Back to top |
|
 |
GDH-gentoo Veteran


Joined: 20 Jul 2019 Posts: 1871 Location: South America
|
Posted: Tue Apr 29, 2025 6:06 pm Post subject: |
|
|
I'm pretty sure openrc shutdown does execute the stop() function of service scripts that correspond to services in the sysinit and boot runlevels. I'll add lvm to the examples given by Alverstone.
I'm not in front of a Gentoo computer right now, but when I am, that should be easy to test with scripts that just print messages. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer  |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though  |
|
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2132
|
Posted: Tue Apr 29, 2025 6:11 pm Post subject: |
|
|
GDH-gentoo wrote: | I'm pretty sure openrc shutdown does execute the stop() function of service scripts that correspond to services in the sysinit and boot runlevels. I'll add lvm to the examples given by Alverstone.
I'm not in front of a Gentoo computer right now, but when I am, that should be easy to test with scripts that just print messages. |
The docs say this is true. But, they don't need to be in most cases. |
|
Back to top |
|
 |
GDH-gentoo Veteran


Joined: 20 Jul 2019 Posts: 1871 Location: South America
|
Posted: Thu May 01, 2025 5:18 pm Post subject: |
|
|
Alverstone wrote: | When the "/sbin/openrc shudown" or "/sbin/openrc reboot" executes, the boot and sysinit runlevels are not stopped. |
GDH-gentoo wrote: | I'm pretty sure openrc shutdown does execute the stop() function of service scripts that correspond to services in the sysinit and boot runlevels. |
Simple test then:
/etc/init.d/test-sysinit
Code: | #!/sbin/openrc-run
depend() {
before killprocs savecache
}
start() { :; }
stop() {
ebegin "Stopping a service in the sysinit runlevel"
sleep 5
eend 0
} | /etc/init.d/test-boot
Code: | #!/sbin/openrc-run
depend() {
before killprocs savecache
}
start() { :; }
stop() {
ebegin "Stopping a service in the boot runlevel"
sleep 5
eend 0
} |
Code: | # rc-update add test-sysinit sysinit
# rc-update add test-boot boot |
Reboot, verify that both services have been started, and then shut down. With OpenRC on top of sysinit, I see both messages when the computer is shutting down. If this doesn't happen with OpenRC on top of runit, then that's a separate problem. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer  |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though  |
|
|
Back to top |
|
 |
|