On 28.08.2022 23:35, Charles wrote:
> Hello,
>
> Adding NAME="mywifi" to an udev rule causes the SYSTEMD_WANTS service to not
> be executed. Removing NAME="mywifi" and the service is executed. How come?
>
>
>> /etc/udev/rules.d/10-network.rules
>> SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="...", TAG+="systemd",
>> ENV{SYSTEMD_WANTS}="test.service"
>
> /etc/systemd/system/test.service
>
>> [Service]
>> Type=simple
>> ExecStart=/bin/echo %n started!
>
> First try, it works:
> I type:
>
>> # journalctl -f -u test.service
>
> I plug the USB Wi-Fi device and it prints:
>
>> "test.service started!"
>
> Note that ip link show returns wlan1.
>
> Now I add NAME="mywifi" which gives:
>
>> /etc/udev/rules.d/10-network.rules
>> SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="...", NAME="mywifi",
>> TAG+="systemd", ENV{SYSTEMD_WANTS}="test.service"
>
> I plug the USB Wi-Fi device and it prints nothing.
> Note that ip link show returns mywifi.
> I remove NAME="mywifi" and it prints "test.service started!" again.
>
My best guess is that rename results in addition uevent which wipes out
previous udev device state including SYTSEMD_WANTS. Try "udevadm
monitor" to see the difference.
General consensus is that you should use
ACTION!="remove"
instead of explicit
ACTION=="add"
unless you really want different rules for different uevents.
> I really do not understand. When using RUN, it works all the time.
> SYSTEMD_WANTS seems to work only when the interface is not renamed. I tried
> also to rename it with a .link file, it got renamed but the service is still
> not triggered.
>
> Hope you can help me out.
> Thanks in advance for your time,
> Charles
>
> Sent with [Proton Mail](https://proton.me/) secure email.