I create a Debian Bookworm machine to serve as LXC containers manager. I use unprivileged LXC containers started with lxc-unpriv-start command that create a systemd user scope. I create a service that start my containers on server start and launch a clean shutdown on service stop. Every container can take 2 or 3 minutes to shutdown. If I stop main service manually all works well. The problem arise when I shutdown the server because my service correctly wait for containers termination but meanwhile systemd-logind kill all user session brutally killing my container also.
I simulate the situation creating a sleep only shell and execute it with
/usr/bin/systemd-run --user --scope -p "Delegate=yes" wait.sh &
and it get killed on shutdown. How can I avoid this kill?
systemctl --user)?