Services asked for by UDEV do not get triggered #7109

Open
tillkamppeter opened this Issue Oct 16, 2017 · 15 comments

Comments

Projects
None yet
4 participants

Submission type

  • Bug report

systemd version the issue has been seen with

234

Used distribution

Ubuntu Artful, 17.10

In case of bug report: Expected behaviour you didn't see

Setting TAG+="systemd" and ENV{SYSTEMD_WANTS}+="..." should make the requested systemd service to be started. See Ubuntu bug report linked below.

In case of bug report: Unexpected behaviour you saw

Service does not get started, but one can start it manually using sudo systemd start ....

In case of bug report: Steps to reproduce the problem

Connect a USB printer. This triggers the UDEV rule file /lib/udev/rules.d/70-printers.rules as shown in the Ubuntu bug report. The printer setup service (and if needed ippusbxd) do not get started. Manually starting the service (exact name in the SYSTEMD_WANTS line of the udevadm monitor --environment) output) with sudo systemd start ... starts the service correctly.

Please see all files, commands, configurations, and discussion up to now in the following Ubuntu bug report:

https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1721839

Especially note that the first assumption was a character escaping problem but fixing the UDEV rules file does not solve the problem. The problem stays as it is.

I will not copy all files and comments to here, see the Ubuntu bug report for them.

Owner

poettering commented Oct 23, 2017

is the dependency from the device unit onto the service unit shown in the "systemctl show" output of the device unit?

Which is the device unit in my case? And which is the service unit?

Attached: Output of

systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540.txt

systemctl-show-deskjet2540.txt

Found the device unit name by some tinkering:

till@till-x1carbon:~$ systemctl list-dependencies 'udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service'
udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service
● ├─cups.socket
● ├─system-udev\x2dconfigure\x2dprinter.slice
● └─sysinit.target
●   ├─apparmor.service
●   ├─console-setup.service
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─friendly-recovery.service
●   ├─keyboard-setup.service
●   ├─kmod-static-nodes.service
●   ├─lvm2-lvmetad.socket
●   ├─lvm2-lvmpolld.socket
●   ├─lvm2-monitor.service
●   ├─plymouth-read-write.service
●   ├─plymouth-start.service
●   ├─proc-sys-fs-binfmt_misc.automount
●   ├─resolvconf.service
●   ├─rpcbind.service
●   ├─setvtrgb.service
●   ├─sys-fs-fuse-connections.mount
●   ├─sys-kernel-config.mount
●   ├─sys-kernel-debug.mount
till@till-x1carbon:~$ systemctl list-dependencies --reverse cups.service
cups.service
● ├─cups-browsed.service
● └─printer.target
●   └─sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
till@till-x1carbon:~$
Owner

poettering commented Oct 24, 2017

So, the relevant line in the "systemctl show" output is this one:

Wants=printer.target udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service

Which doesn't really match what you are expecting, right? Because that is udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service

And I got the above result with the corrected 70-printers.rules file:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

See the

ENV{SYSTEMD_WANTS}+="'%c'"

at the end of the first rule.

Owner

poettering commented Oct 25, 2017

btw, you really should use systemd-escape's --path argument for cases like this

I tried adding --path now. The /lib/udev/rules.d/70-printers.rules looks like this now:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --path --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

As this also removes the leading slash from the path inserted in the service name I counteract this by adding a slash at the appropriate place in the udev-configure-printer command line in /lib/systemd/system/udev-configure-printer@.service making the file look like this:

[Unit]
Description=Automatic USB/Bluetooth printer setup (%i)
Requires=cups.socket
After=cups.socket

[Service]
#Type=simple
Type=forking
GuessMainPID=true
ExecStart=/lib/udev/udev-configure-printer add /%I
# This ExecStop would be useful to disable the print queue when ippusbxd
# crashes or gets killed, but in the case that ippusbxd does not get started
# at all during the process run by ExecStart (printer does not support
# IPP-over-USB) ExecStop gets run immediately making a printer getting
# disabled again right after it getting enabled or set up
# ExecStop=/lib/udev/udev-configure-printer remove %I

Result is the same. Service does not start when plugging the printer but with printer plugged one can start it manually with sudo systemctl start ....

Problem is still with the escaping and unescaping. udevadm monitor --environment while plugging contains correct

SYSTEMD_WANTS='udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service' printer.target

(note that service name has changed slightly, no - between @ and devices, used this device name when successfully started the service manually).
systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540-2.txt still shows the wrong unescaping:

SysFSPath=/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2
Id=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Names=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service
Description=Deskjet_2540_series
LoadState=loaded
ActiveState=active
SubState=plugged
StateChangeTimestamp=Wed 2017-10-25 08:21:54 -02
StateChangeTimestampMonotonic=3690016
InactiveExitTimestamp=Wed 2017-10-25 08:21:54 -02
InactiveExitTimestampMonotonic=3690016
ActiveEnterTimestamp=Wed 2017-10-25 08:21:54 -02
ActiveEnterTimestampMonotonic=3690016
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=1min 30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
Perpetual=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
InvocationID=4ed24799e889439cbb5a929fdbaa8189

Relevant line:

Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service
Owner

poettering commented Oct 26, 2017

Use %f in unit files, to undo the escaping systemd-escape --path does

%f also does not work, same result as before.

poettering added a commit to poettering/systemd that referenced this issue Oct 26, 2017

core: when a unit template is specified in SYSTEMD_WANTS=, instantiat…
…e it with sysfs path

This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.

I have applied the patch now and tried again, without success. The /lib/udev/rules.d/70-printers.rules looks like this now:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --path --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

The /lib/systemd/system/udev-configure-printer@.service contains:

[Unit]
Description=Automatic USB/Bluetooth printer setup (%f)
Requires=cups.socket
After=cups.socket

[Service]
#Type=simple
Type=forking
GuessMainPID=true
ExecStart=/lib/udev/udev-configure-printer add /%f
# This ExecStop would be useful to disable the print queue when ippusbxd
# crashes or gets killed, but in the case that ippusbxd does not get started
# at all during the process run by ExecStart (printer does not support
# IPP-over-USB) ExecStop gets run immediately making a printer getting
# disabled again right after it getting enabled or set up
# ExecStop=/lib/udev/udev-configure-printer remove /%f

In this file I also tried %I and %i instead of %f, with the same unsuccessful result.
In the output of udevadm monitor --environment I get

DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2
SYSTEMD_WANTS='udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service' printer.target

With

systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540-6.txt

I get

SysFSPath=/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2
Id=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Names=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service
[...]

and in /var/log/syslog the following appears:

Oct 26 17:52:56 till-x1carbon systemd[1]: Starting Automatic USB/Bluetooth printer setup (/devices/pci0000:00/0000:00:14.0/usb2/2x2d2)...
Oct 26 17:52:56 till-x1carbon udev-configure-printer[6479]: add //devices/pci0000:00/0000:00:14.0/usb2/2x2d2
Oct 26 17:52:56 till-x1carbon udev-configure-printer[6479]: unable to access /sys//devices/pci0000:00/0000:00:14.0/usb2/2x2d2
Oct 26 17:52:56 till-x1carbon systemd[1]: udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service: Control process exited, code=exited status=1
Oct 26 17:52:56 till-x1carbon systemd[1]: Failed to start Automatic USB/Bluetooth printer setup (/devices/pci0000:00/0000:00:14.0/usb2/2x2d2).
Oct 26 17:52:56 till-x1carbon systemd[1]: udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service: Unit entered failed state.

This means that udev-configure-printer gets called but the backslash gets lost somewhere and so the unescaping does not work.

lulandco commented Nov 5, 2017

Hi,
Same here. My service unit (without instance) is no more triggered by udev in artful on usb plug. BUT, it reworks when I plug the device in another usb port. One used usb port can't be reused to trigger the service unit except restarting the system. Could It be a udev issue ?

poettering added a commit to poettering/systemd that referenced this issue Nov 9, 2017

core: when a unit template is specified in SYSTEMD_WANTS=, instantiat…
…e it with sysfs path

This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.

poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017

core: when a unit template is specified in SYSTEMD_WANTS=, instantiat…
…e it with sysfs path

This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.

poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017

core: when a unit template is specified in SYSTEMD_WANTS=, instantiat…
…e it with sysfs path

This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.

poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017

core: when a unit template is specified in SYSTEMD_WANTS=, instantiat…
…e it with sysfs path

This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.

@poettering, what do you want with the patches 2460091 and
2273473? They are absolutely identical with the patch
f92d2d1 from 15 days ago which I tested and which did not solve the problem for me.

tillkamppeter commented Nov 10, 2017

Also the patches fec1261 and dcebc9b are the same as the first patch which did not work for me.

Anything news on this?

i found the device units is still exist after printer unplugged

systemctl list-units | grep Printer
sys-devices-pci0000:00-0000:00:1d.0-usb2-2\x2d1-2\x2d1.2.device             loaded active plugged   Printer
printer.target                                                              loaded active active    Printer

but there is no 2-1.2 actually

ls /sys/devices/pci0000\:00/0000\:00\:1d.0/usb2/2-1/
2-1:1.0            bcdDevice            bDeviceSubClass  bNumConfigurations  descriptors  driver     ltm_capable  quirks     subsystem
2-1.5              bConfigurationValue  bmAttributes     bNumInterfaces      dev          ep_00      maxchild     removable  uevent
authorized         bDeviceClass         bMaxPacketSize0  busnum              devnum       idProduct  port         remove     urbnum
avoid_reset_quirk  bDeviceProtocol      bMaxPower        configuration       devpath      idVendor   power        speed      version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment