<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hello,</p>
<p><br>
</p>
<p>I want a service which executes 'startFoo.sh' exactly like a user 'Foo' would experience it. This is my current approach:<br>
</p>
<blockquote>
<p><span style="font-family:"Courier New",monospace">[Service]</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">ExecStart=/usr/bin/startFoo.sh</span></p>
<p><span style="font-family:"Courier New",monospace">User=Foo</span></p>
<p><span style="font-family:"Courier New",monospace">PAMName=login</span></p>
</blockquote>
<p><br>
</p>
<p>And it seems to work just fine. But I can't figure out how to stop this service and all of its childs in a clean way. According to the systemd.exec documentation this service will start a 'session scope' CGroup but it does not mention how to stop this when
 the service stops. So far I found this workaround:</p>
<p>I add a </p>
<blockquote>
<p><span style="font-family:"Courier New",monospace">ExecStop=/usr/bin/stopFoo.sh
</span></p>
</blockquote>
<p>to the main service which does that:</p>
<blockquote><span style="font-family:"Courier New",monospace"><span style="color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:"Courier New",monospace"><span style="font-family:"Courier New",monospace">#!/bin/bash
</span></span></span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace"><span style="font-family:"Courier New",monospace">systemctl stop $(systemctl status $(pidof <anyProcessNameInsideTheChildCGroup>) | grep user.*slice | grep -o session.*scope)</span></span><br>
<span style="font-family:monospace"></span></blockquote>
<p><br>
</p>
<p>Is there a clean solution to accomplish something like this? </p>
<p><br>
</p>
<p>Thanks and Kind Regards,<br>
</p>
Michael Dluhosch
<p><br>
</p>
<font style="font-size: 9px;">The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised.<br>If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.<br>Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.<br>All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.</font></body>
</html>