<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR link="#0563C1" vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’m using debian 10 (systemd 241) . I launch a service (tank.service) when a specific USB device is connected. For that, i have written an udev rule that requests the service start in case of « add » event, thanks to « SYSTEMD_WANTS » :<o:p></o:p></p><p class=MsoNormal><i>SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="6570", TAG+="systemd", ENV{SYSTEMD_WANTS}="tank.service"<o:p></o:p></i></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I want service to be stopped when the USB device is removed. For that, I use « StopWhenUnneeded » feature.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>tank.service : <o:p></o:p></p><p class=MsoNormal><i><span style='color:#4472C4'>[Unit]<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>Description= tank routine<o:p></o:p></span></i></p><p class=MsoNormal><b><i><span style='color:#4472C4'>StopWhenUnneeded=true<o:p></o:p></span></i></b></p><p class=MsoNormal><i><span style='color:#4472C4'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>[Service]<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>Type=simple<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>ExecStartPre=-/bin/bash /actimyo/bin/tankinsert.sh<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>ExecStart=/bin/bash /actimyo/bin/tank.sh<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'>ExecStop=/bin/bash /actimyo/bin/tankremove.sh<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#4472C4'><o:p> </o:p></span></i></p><p class=MsoNormal>With kernel 4.9.150 , it works well : the service is stopped when the USB device is removed. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>However, I updated the kernel to version 5.15.32 and the service do not stop when the USB device is removed . The feature « StopWhenUnneeded » no longer works. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Does anybody understand why ? Could anybody give me a solution ?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><u>Systemd logs when USB device is removed with kernel 4.9.150 (complete logs in attached file « logs systemd removing tank-4-9-150.txt ») :<o:p></o:p></u></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 kernel: usb 1-1: USB disconnect, device number 2<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 kernel: usb 1-1.2: USB disconnect, device number 3<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Unit is not needed anymore.<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Trying to enqueue job tank.service/stop/fail<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Added job tank.service/stop to transaction.<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Installed new job tank.service/stop as 724<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Enqueued job tank.service/stop as 724<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1/unit/tank_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=605 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1/unit/tank_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=606 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=JobNew cookie=607 reply_cookie=0 signature=uos error-name=n/a error-message=n/a<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: About to execute: /bin/bash /actimyo/bin/tankremove.sh<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Forked /bin/bash as 2496<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1/unit/tank_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=608 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1/unit/tank_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=609 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Changed running -> stop<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[1]: Stopping Detect tank presence...<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:34 b-0024 systemd[2496]: tank.service: Executing: /bin/bash /actimyo/bin/tankremove.sh<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><u>Systemd logs</u> <u>when USB device is removed with kernel 5.15.32 (complete logs in attached file « logs systemds removing tank kernel-5-15-32.txt »):</u><o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:33 b-0021 kernel: [ 438.934344] usb 1-1: USB disconnect, device number 2<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:33 b-0021 kernel: [ 438.939373] usb 1-1.2: USB disconnect, device number 3<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:33 b-0021 systemd[1]: tank.service: tank.service lost dependency WantedBy=sys-devices-platform-soc-2100000.bus-2184000.usb-ci_hdrc.0-usb1-1\x2d1.device<o:p></o:p></p><p class=MsoNormal>Jun 17 09:21:33 b-0021 systemd[1]: tank.service: tank.service lost dependency ReferencedBy=sys-devices-platform-soc-2100000.bus-2184000.usb-ci_hdrc.0-usb1-1\x2d1.device<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Best regards<o:p></o:p></p><p class=MsoNormal style='background:white'><span lang=EN-US style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#666666;mso-fareast-language:FR'>---<br>Eric-Olivier Perrin<br></span><span style='color:black'><a href="mailto:eric-olivier.perrin@sysnav.fr" target="_blank"><span lang=EN-US style='font-size:12.0pt;font-family:"Arial",sans-serif;color:blue;mso-fareast-language:FR'>eric-olivier.perrin@sysnav.fr</span></a></span><span lang=EN-US style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#666666;mso-fareast-language:FR'><o:p></o:p></span></p><p class=MsoNormal style='background:white'><span style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#666666;mso-fareast-language:FR'>--------------------------------------------<br>SYSNAV<br>72, rue Emile Loubet<br>27200 Vernon (France)<br>+33.(0)2.78.77.03.46<o:p></o:p></span></p><p class=MsoNormal style='background:white'><span style='color:black'><a href="http://www.sysnav.com/en/" target="_blank"><span style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#1155CC;mso-fareast-language:FR'>www.sysnav.com</span></a></span><span style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#666666;mso-fareast-language:FR'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Arial",sans-serif;color:#666666;mso-fareast-language:FR'>--------------------------------------------</span><span style='mso-fareast-language:FR'><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>