From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/2647 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Guillermo Newsgroups: gmane.comp.sysutils.supervision.general Subject: s6-linux-init: Actions after unmounting filesystems Date: Sat, 17 Aug 2019 16:14:03 -0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="11612"; mail-complaints-to="usenet@blaine.gmane.org" To: Supervision Original-X-From: supervision-return-2237-gcsg-supervision=m.gmane.org@list.skarnet.org Sat Aug 17 21:14:19 2019 Return-path: Envelope-to: gcsg-supervision@m.gmane.org Original-Received: from alyss.skarnet.org ([95.142.172.232]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hz49b-0002t6-6b for gcsg-supervision@m.gmane.org; Sat, 17 Aug 2019 21:14:19 +0200 Original-Received: (qmail 19754 invoked by uid 89); 17 Aug 2019 19:14:40 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm Original-Sender: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Original-Received: (qmail 19747 invoked from network); 17 Aug 2019 19:14:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=gsM3qPNypHLUI2ZskGeB3A0weTpLOpToDmnck0p+IKY=; b=oyTtTD8SiG4Sdx4BtlInVkzTAiqrcCv8qwPV5s2IJ2yknN9hAZKS2klN6weN8oiDob z16W9B8cJtVJNVxQadKRh35aUksdAgHpYkfJRXnQCNxf8TiWh8tIZ3sAeyuQBE9TY2+L 8/RDqsxBbf5+kUMcS6f3mBKrSOd0UpXU9kL58iIn6s9v79MDxDwSO3AilX3TYeRkU+G3 JGKpJk6d6gLtZy3CjWjJtNQGn8ojDaPhD79SdDfjhI1R55lx5P8jv3NXt6/3sTM5MhwS JTIrXeft6n4hqHaAYcbj1vWu2vUAI0FPbKr7uMA2pIGESL3FvryV5/Gn7C23N7ofyT6I 9ywA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=gsM3qPNypHLUI2ZskGeB3A0weTpLOpToDmnck0p+IKY=; b=TrDe8zepufIGQh+29NN9ezDjbq25Zmn2g5F1ma5N6B2/RuOOATzzUecip5+E58Ft28 6ivUIqFHaa5FHsEGApo040ZoQhMQN/crK1yub2fnnp15mKe17U5JeM/JVpac6VDUkV3B J9vOHBEQrY8TPIjk6V1LEK/r5Clj3/hUZH0Nf99j3/05It7qeczW6CKrWuYek8KpzBc1 vcMiTnv9VaDVipOUqQjjT5ZvL+Pof6ruIeE1Cgdt3XBWozy79PHWk89oUnRfiuPKLrTu 753vmOOLtJrH0tMqQWgKH5mbXvEgD/RsQVnhNzloiA6a0GCdRwOe6m3FwOwzoW1q8QAj YQJw== X-Gm-Message-State: APjAAAXNuVXdXnwY5Z934bswFAQCEhcYDF88IP1d+DnbpDJ5m7EF3Ohz p3vbaHLj3BtOjGxaITACwGZbCQXFQjvCaFiGWJlj3g== X-Google-Smtp-Source: APXvYqyGCstBdTl9SOi7jXjrhepRabEpXQ9haKAzLQxkIHbmoYkjwMc5ax28NqDnAVzntTidoTBfJCl6ZBU19w1ds/I= X-Received: by 2002:a6b:4107:: with SMTP id n7mr5470771ioa.12.1566069252876; Sat, 17 Aug 2019 12:14:12 -0700 (PDT) Xref: news.gmane.org gmane.comp.sysutils.supervision.general:2647 Archived-At: 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/0566391df8c9c93f75ad99d94c8= a19abe379908b/3#L37 deactivate_vgs and deactivate_crypt are defined in /etc/runit/functions: * https://github.com/void-linux/void-runit/blob/0566391df8c9c93f75ad99d94c8= a19abe379908b/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=C3=A9lie 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/b1eb50599e4db7eb4501af75cbbfa2= 2007081ea5/system/lvm2/lvm.initd * https://code.foxkit.us/adelie/packages/raw/49602ddb82f87067bbb945fc2a814a= 8eb6d6aabe/system/cryptsetup/dmcrypt.initd I can't verify without actually installing Ad=C3=A9lie, but I suppose these are also boot runlevel services. However, it appears that Ad=C3=A9lie'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.