[systemd-devel] How to stop child cgroup caused by PAMName=
Tomasz Pala
gotar at polanet.pl
Thu Feb 6 10:35:36 UTC 2025
On Thu, Feb 06, 2025 at 08:25:06 +0000, Dluhosch, Michael wrote:
> PAMName=login
[...]
> ExecStop=/usr/bin/stopFoo.sh
>
> to the main service which does that:
>
> #!/bin/bash
Don't use bash for scripts.
> systemctl stop $(systemctl status $(pidof <anyProcessNameInsideTheChildCGroup>) | grep user.*slice | grep -o session.*scope)
I'm using:
ExecStop=/bin/sh -c "loginctl kill-session --signal SIGTERM `systemctl -n1 -o export status \"$MAINPID\" | grep _SYSTEMD_SESSION | cut -f2 -d=`"
ExecStopPost=/bin/sh -c "loginctl terminate-session `systemctl -n1 -o export status \"$MAINPID\" | grep _SYSTEMD_SESSION | cut -f2 -d=`"
This would be much easier if systemd provided $_SYSTEMD_SESSION variable directly:
ExecStop=loginctl kill-session --signal SIGTERM $_SYSTEMD_SESSION
or made this directly accessibe via some kind of:
KillMode=session
--
Tomasz Pala <gotar at pld-linux.org>
More information about the systemd-devel
mailing list