[systemd-devel] systemd has not the same behaviour following the version of the kernel ; StopWhenUnneeded no longer works
Colin Guthrie
gmane at colin.guthr.ie
Wed Sep 28 16:17:55 UTC 2022
Long standing issue with udev rules and a kernel change.
IIRC you should try ACTION!="remove" in your udev rule instead.
There are other posts on the list about this but I'm running out the
door so thought I'd through a hint at least - if it doesn't work, I may
have got the action name wrong, so look around!
Cheers
Col
eric-olivier.perrin at sysnav.fr wrote on 27/09/2022 16:16:
> Hi,
>
> 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 » :
>
> /SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="04b4",
> ATTRS{idProduct}=="6570", TAG+="systemd", ENV{SYSTEMD_WANTS}="tank.service"/
>
> I want service to be stopped when the USB device is removed. For that, I
> use « StopWhenUnneeded » feature.
>
> tank.service :
>
> /[Unit]/
>
> /Description= tank routine/
>
> */StopWhenUnneeded=true/*
>
> //
>
> /[Service]/
>
> /Type=simple/
>
> //
>
> /ExecStartPre=-/bin/bash /actimyo/bin/tankinsert.sh/
>
> /ExecStart=/bin/bash /actimyo/bin/tank.sh/
>
> /ExecStop=/bin/bash /actimyo/bin/tankremove.sh/
>
> //
>
> With kernel 4.9.150 , it works well : the service is stopped when the
> USB device is removed.
>
> 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.
>
> Does anybody understand why ? Could anybody give me a solution ?
>
> _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 ») :_
>
> Jun 17 09:21:34 b-0024 kernel: usb 1-1: USB disconnect, device number 2
>
> Jun 17 09:21:34 b-0024 kernel: usb 1-1.2: USB disconnect, device number 3
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Unit is not needed anymore.
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Trying to enqueue job
> tank.service/stop/fail
>
> Jun 17 09:21:34 b-0024 systemd[1]: Added job tank.service/stop to
> transaction.
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Installed new job
> tank.service/stop as 724
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Enqueued job
> tank.service/stop as 724
>
> 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
>
> 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
>
> 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
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: About to execute:
> /bin/bash /actimyo/bin/tankremove.sh
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Forked /bin/bash as 2496
>
> 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
>
> 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
>
> Jun 17 09:21:34 b-0024 systemd[1]: tank.service: Changed running -> stop
>
> Jun 17 09:21:34 b-0024 systemd[1]: Stopping Detect tank presence...
>
> Jun 17 09:21:34 b-0024 systemd[2496]: tank.service: Executing: /bin/bash
> /actimyo/bin/tankremove.sh
>
> _Systemd logs_ _when USB device is removed with kernel 5.15.32 (complete
> logs in attached file « logs systemds removing tank kernel-5-15-32.txt »):_
>
> Jun 17 09:21:33 b-0021 kernel: [ 438.934344] usb 1-1: USB disconnect,
> device number 2
>
> Jun 17 09:21:33 b-0021 kernel: [ 438.939373] usb 1-1.2: USB disconnect,
> device number 3
>
> 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
>
> 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
>
> Best regards
>
> ---
> Eric-Olivier Perrin
> eric-olivier.perrin at sysnav.fr <mailto:eric-olivier.perrin at sysnav.fr>
>
> --------------------------------------------
> SYSNAV
> 72, rue Emile Loubet
> 27200 Vernon (France)
> +33.(0)2.78.77.03.46
>
> www.sysnav.com <http://www.sysnav.com/en/>
>
> --------------------------------------------
>
--
Colin Guthrie
More information about the systemd-devel
mailing list