3

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?

Gauthier
  • 870

2 Answers2

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.

Gauthier
  • 870
  • 4
    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 04 '19 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.

AdminBee
  • 22,803
  • Thanks. I read this http://blog.fraggod.net/2012/06/16/proper-ish-way-to-start-long-running-systemd-service-on-udev-event-device-hotplug.html , which is doing what I'm trying. They advice against using systemctl start at the bottom, which I tend to agree with. – Gauthier Nov 04 '19 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 04 '19 at 12:09
  • 1
    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 04 '19 at 17:36