From: Guillermo <gdiazhartusch@gmail.com>
To: Supervision <supervision@list.skarnet.org>
Subject: s6-linux-init: Actions after unmounting filesystems
Date: Sat, 17 Aug 2019 16:14:03 -0300 [thread overview]
Message-ID: <CADQ2Nw85w2Ny-E_d2gQdmTi0mhYaU68S6giOQs3h31WafS4Q-Q@mail.gmail.com> (raw)
For the 0.4.x.x series of s6-linux-init, the shutdown sequence model
was that s6-svscan replaced itself with a 'stage3 init' that ran as
process 1 until the machine halted, powered off, or rebooted. The
stage3 init was an execline script.
s6-linux-init-1.0.0.0 and later, among other things, has changed the
shutdown sequence model. The new one is that a supervised 'shutdown
daemon', s6-linux-init-shutdownd, performs all shutdown tasks, and
s6-svscan remains process 1 until the machine halts, powers off, or
reboots. s6-linux-init-shutdownd is a C program.
In both models, all processes are killed with a 'kill(-1, SIGTERM)'
call and then a 'kill(-1, SIGKILL)' call, and then filesystems are
unmounted. For the 0.4.x.x series, this is done by having the stage3
init run a program. Because the stage3 init runs as process 1, it
survives the SIGKILL. For s6-linux-init-1.0.0.0 and later, this is
done directly by s6-linux-init-shutdownd. Because
s6-linux-init-shutdownd is part of a supervision tree rooted in
process 1, it is respawned after the SIGKILL, and then completes the
shutdown sequence.
There are certain setups that require doing something after
filesystems are unmounted. Two examples are LVM logical volumes and
LUKS encrypted volumes, but I suppose there must be more cases. In any
such setup, the shutdown sequence would include a 'vgchange -a n'
command or 'cryptsetup close' command after filesystems are unmounted.
Runit-based Void Linux does this in /etc/runit/3:
* https://github.com/void-linux/void-runit/blob/0566391df8c9c93f75ad99d94c8a19abe379908b/3#L37
deactivate_vgs and deactivate_crypt are defined in /etc/runit/functions:
* https://github.com/void-linux/void-runit/blob/0566391df8c9c93f75ad99d94c8a19abe379908b/functions#L38
Gentoo, and I suppose that other OpenRC-based distributions as well,
leave this to the service manager. OpenRC-provided 'localmount'
service uses 'fuser -m -k' and umount commands in its stop() function
to unmount filesystems, and 'killprocs' service takes care of every
remaining process using OpenRC's internal kill_all command. Gentoo
then adds services named 'lvm' and 'dmcrypt' to OpenRC's boot
runlevel, and service ordering at shutdown, enforced by specifications
in service's depend() functions and OpenRC's runlevels model, is
localmount < root (a no-op) < fsck (a no-op generally) < {lvm,
dmcrypt} < killprocs < mount-ro, where "<" means "precedes" here.
How would something like this fit in s6-linux-init's new shutdown
model? In the old one, just like in runit's case, I suppose it could
be done in 'shutdown hooks' called by the execline stage3 init.
Something like:
foreground {
redirfd -r 0 shutdown-hooks.conf
forstdin shutdown_hook
importas -u shutdown_hook shutdown_hook
if -nX { $shutdown_hook }
echo stage3 init: warning: shutdown hook \"${shutdown_hook}\" failed
}
I also looked at Adélie Linux, which currently uses
s6-linux-init-1.0.2.1 + OpenRC if it is configured to do so, and it
seems to copy Gentoo in this case. It also has lvm and dmcrypt OpenRC
service scripts:
* https://code.foxkit.us/adelie/packages/raw/b1eb50599e4db7eb4501af75cbbfa22007081ea5/system/lvm2/lvm.initd
* https://code.foxkit.us/adelie/packages/raw/49602ddb82f87067bbb945fc2a814a8eb6d6aabe/system/cryptsetup/dmcrypt.initd
I can't verify without actually installing Adélie, but I suppose these
are also boot runlevel services. However, it appears that Adélie's
/etc/s6-linux-init/skel/rc.shutdown just asks OpenRC to enter a custom
runlevel named 'empty'. Because this isn't the shutdown runlevel, if I
understand correctly this would neither stop boot runlevel services,
nor start shutdown runlevel services, so OpenRC's localmount,
killprocs and mount-ro would not interfere with s6-linux-init's
shutdown procedure. But doesn't this also mean that the vgchange and
cryptsetup invocations in lvm's and dmcrypt's stop() functions would
never happen?
G.
next reply other threads:[~2019-08-17 19:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-17 19:14 Guillermo [this message]
2019-08-17 23:01 ` Laurent Bercot
2019-08-18 4:09 ` Casper Ti. Vector
[not found] ` <20190818040925.yqy4nm7cwsnrtyjl@caspervector>
2019-08-18 6:26 ` Laurent Bercot
2019-08-18 8:34 ` Casper Ti. Vector
2019-08-18 16:18 ` Samuel Holland
2019-08-18 18:35 ` Laurent Bercot
2019-08-18 19:28 ` Guillermo
2019-08-18 20:36 ` Oliver Schad
2019-08-18 15:08 ` Guillermo
2019-08-18 21:36 ` Brett Neumeier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADQ2Nw85w2Ny-E_d2gQdmTi0mhYaU68S6giOQs3h31WafS4Q-Q@mail.gmail.com \
--to=gdiazhartusch@gmail.com \
--cc=supervision@list.skarnet.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).