From a375e145190482e8a2f0971bffb332e31211622f Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 10 Oct 2024 21:32:17 +0200 Subject: [PATCH] units/{user,capsule}@.service: issue daemon-reexec when notify-reloading Closes #28367 (but not really in the exact form, see below) We have the problem of restarting all user manager instances after upgrade. Current approaches involve systemctl kill with SIGRTMIN+25, which is async and feels rather ugly [1][2]; or systemctl --machine=user@ --user, which requires entering each user session. Neither is particularly elegant. Instead, let's just signal daemon-reexec when user@.service is reloaded from system manager. Our long goal of dropping daemon-reload in favor of reexec (see TODO) is unlikely to happen due to user dbus restrictions, but here the synchronization is done via READY=1. [1] https://gitlab.archlinux.org/archlinux/packaging/packages/systemd/-/blob/main/systemd.install?ref_type=heads#L37 [2] https://salsa.debian.org/systemd-team/systemd/-/blob/debian/master/debian/systemd.postinst#L24 #28367 would not really work for us now I come to think about it, because all processes will be reparented to pid1 as soon as original user manager process exits. This alternative approach seems good enough for our use case. --- units/capsule@.service.in | 4 ++++ units/user@.service.in | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/units/capsule@.service.in b/units/capsule@.service.in index f2bb9e3a45a..a64298786e4 100644 --- a/units/capsule@.service.in +++ b/units/capsule@.service.in @@ -23,6 +23,10 @@ StateDirectory=capsules/%i RuntimeDirectory=capsules/%i LogExtraFields=CAPSULE=%i Slice=capsule.slice +# Reexecute the manager on service reload, instead of reloading. +# This provides a synchronous method for restarting all user manager +# instances after upgrade. +ReloadSignal=RTMIN+25 KillMode=mixed Delegate=pids memory cpu DelegateSubgroup=init.scope diff --git a/units/user@.service.in b/units/user@.service.in index 56954657472..381ab2a0db5 100644 --- a/units/user@.service.in +++ b/units/user@.service.in @@ -20,6 +20,10 @@ PAMName=systemd-user Type=notify-reload ExecStart={{LIBEXECDIR}}/systemd --user Slice=user-%i.slice +# Reexecute the manager on service reload, instead of reloading. +# This provides a synchronous method for restarting all user manager +# instances after upgrade. +ReloadSignal=RTMIN+25 KillMode=mixed Delegate=pids memory cpu DelegateSubgroup=init.scope