1

I am modifying my working udev rule (/etc/udev/rules.d/10-local.rules):

SUBSYSTEM=="tty", ATTRS{idVendor}=="1366", ATTRS{idProduct}=="1015", ATTRS{serial}=="000621000000", SYMLINK+="ttymkw"

to this (end of row):

SUBSYSTEM=="tty", ATTRS{idVendor}=="1366", ATTRS{idProduct}=="1015", ATTRS{serial}=="000621000000", SYMLINK+="ttymkw", TAG+="systemd", SYSTEMD_WANTS="offnet-uart-log.service"

I have user service offnet-uart-log.service in ~/.config/systemd/user, which I can manually trigger, but I don't get this far yet.

With the added , TAG+="systemd", SYSTEMD_WANTS="offnet-uart-log.service" at the end of my udev rule, the symlink is not created (I reload with sudo udevadm control --reload-rules && sudo udevadm trigger).

This tells me that the rule is wrong, but I don't know why. Could be related to udev being owned by root, while the service is owned by the user? Did I misunderstand WANTS?

I've tried all four combinations of SYSTEM_USER_WANTS or SYSTEM_WANTS, and = or +=. Removing the *_WANTS makes the symlink appear, so the error is in the *_WANTS.

How do I make my tty device trigger the log service?


EDIT: as mentioned in my own answer below, modifying SYSTEM_USER_WANTS to ENV{SYSTEM_USER_WANTS} works. Why is it required?

1

This blog post does what I want, and thanks to it I replaced SYSTEMD_USER_WANTS with ENV{SYSTEMD_USER_WANTS}, which made it work.

I still don't understand why the ENV{} construct is needed, and why I haven't found it in the docs.

  • 2
    If you look at man 7 udev, you'll see that SYSTEMD_USER_WANTS isn't valid in a udev rule, while ENV sets a device property value (and systemd uses this property value for its purposes). – dirkt Nov 4 at 12:56
0

If you really just want to trigger a service, you would add

RUN{program}="/bin/systemctl --user start offnet-uart-log.service"

to your udev rule. This would require that your service is of type oneshot or exec, so that the call to systemd returns within the usual short timeframe allowed by udev (see e.g. discussions here How to run long time process on Udev event? and on other pages discussing udev and automatic mounts.

  • Thanks. I read this blog.fraggod.net/2012/06/16/… , which is doing what I'm trying. They advice against using systemctl start at the bottom, which I tend to agree with. – Gauthier Nov 4 at 11:48
  • I agree, that looks like the more proper way to do it (although the approach I suggested worked for me so far). – AdminBee Nov 4 at 12:09
  • I suggest tacking on --no-block. Udev does NOT like latency. And running systemctl has it's uses if you need something to run every time guaranteed, like display mirroring. – davolfman Nov 4 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.