我在跑Ubuntu 18.4我遇到了一个问题,即一个脚本在被触发时拒绝运行udev 规则。
情况就是这样:我在 Surface Pro 4 上运行。此设备有一个可拆卸键盘。我运行一个名为libinput-手势。每当键盘被拆下并重新连接时,手势将不起作用。手动修复相当容易,使用:
libinput-gestures-setup restart
所以脚本我尝试运行的正是这个。下面是它的全部功能:
#!/bin/sh
libinput-gestures-setup restart
我想在添加udev 规则的事件。以下是 .rules 文件:
ACTION=="add", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="07e8", RUN+="/home/$myuser/.bin/gestures-restart"
连接键盘后,找到脚本并运行正常。但记录的内容如下:
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.005043] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.005047] usb 1-7: Product: Surface Type Cover
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.005050] usb 1-7: Manufacturer: Microsoft
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.013813] input: Microsoft Surface Type Cover Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:045E:07E8.000D/input/input95
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.072209] input: Microsoft Surface Type Cover Consumer Control as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:045E:07E8.000D/input/input97
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.072444] input: Microsoft Surface Type Cover Touchpad as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:045E:07E8.000D/input/input99
Apr 20 22:20:51 mb-Surface-Pro-4 kernel: [ 2248.072881] hid-multitouch 0003:045E:07E8.000D: input,hiddev1,hidraw2: USB HID v1.11 Keyboard [Microsoft Surface Type Cover] on usb-0000:00:14.0-7/input0
Apr 20 22:20:51 mb-Surface-Pro-4 mtp-probe: checking bus 1, device 11: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-7"
Apr 20 22:20:51 mb-Surface-Pro-4 mtp-probe: bus: 1, device: 11 was not an MTP device
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5965]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5965]: message repeated 2 times: [ Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.]
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5982]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5993]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5965]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5992]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5991]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5982]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[6011]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5965]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5992]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5993]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[5991]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 systemd-udevd[6015]: Process '/home/mariusb/.bin/gestures-restart' failed with exit code 1.
Apr 20 22:20:51 mb-Surface-Pro-4 upowerd[868]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:045E:07E8.000D
Apr 20 22:20:51 mb-Surface-Pro-4 upowerd[868]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0
Apr 20 22:20:51 mb-Surface-Pro-4 upowerd[868]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7
所以看起来脚本是这里的问题。这就是我需要帮助的地方,因为我不明白哪里出了问题。
作为附加信息:当我安装 libinput 时,我必须将我的用户添加到组中库输入。也许和这个有关
无论如何,提前致谢
编辑: 这似乎与用户未运行该脚本有关。journalctl -xe 打印以下内容:
-- Unit gestures-restart.service has begun starting up.
Apr 20 23:05:44 mb-Surface-Pro-4 gestures-restart[3550]: Non-installation commands must be run as your own user.
Apr 20 23:05:44 mb-Surface-Pro-4 systemd[1]: gestures-restart.service: Main process exited, code=exited, status=1/FAILURE
Apr 20 23:05:44 mb-Surface-Pro-4 systemd[1]: gestures-restart.service: Failed with result 'exit-code'.
Apr 20 23:05:44 mb-Surface-Pro-4 systemd[1]: Failed to start Restart gestures.
-- Subject: Unit gestures-restart.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit gestures-restart.service has failed.
--
-- The result is RESULT.
现在有人知道如何解决这个问题吗?
编辑/更新2:
我让服务检测到我的键盘的连接。它运行良好并按要求执行重启脚本。因此,为了保持最新状态:这是我现在的服务:
[Unit]
Description=Service for restarting gestures
Requires=dev-input-by\x2dpath-pci\x2d0000:00:14.0\x2dusb\x2d0:7:1.0\x2devent\x2dmouse.device
After=dev-input-by\x2dpath-pci\x2d0000:00:14.0\x2dusb\x2d0:7:1.0\x2devent\x2dmouse.device
[Service]
Type=simple
User=$user
ExecStart=/home/$user/.bin/gestures-restart.sh
[Install]
WantedBy=dev-input-by\x2dpath-pci\x2d0000:00:14.0\x2dusb\x2d0:7:1.0\x2devent\x2dmouse.device
libinput-gestures -l 提供了有关该应用程序的一些信息,其中之一是:
libinput-gestures: device /dev/input/by-path/pci-0000:00:14.0-usb-0:7:1.0-event-mouse(event6): Microsoft Surface Type Cover Touchpad
据我了解,这是软件用作输入的设备。所以我使用systemctl list-units
并找到了这个设备:
sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d7-1\x2d7:1.0-0003:045E:07E8.0004-input-input29-event6.device
(我通过 event6 属性识别它)并将其用于服务 REQUIRE/AFTER...
到目前为止,一切看起来都很好。当我拆下并重新连接键盘时,journalctl -xe 输出以下内容:
Apr 21 15:22:13 mb-Surface-Pro-4 systemd[1]: Found device Surface_Type_Cover.
-- Subject: Unit dev-input-by\x2dpath-pci\x2d0000:00:14.0\x2dusb\x2d0:7:1.0\x2devent\x2dmouse.device has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit dev-input-by\x2dpath-pci\x2d0000:00:14.0\x2dusb\x2d0:7:1.0\x2devent\x2dmouse.device has finished starting up.
--
-- The start-up result is RESULT.
Apr 21 15:22:13 mb-Surface-Pro-4 upowerd[886]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:045E:07E8.0011
Apr 21 15:22:13 mb-Surface-Pro-4 systemd[1]: Started Service for restarting gestures.
-- Subject: Unit gestures-restart.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit gestures-restart.service has finished starting up.
--
-- The start-up result is RESULT.
Apr 21 15:22:13 mb-Surface-Pro-4 upowerd[886]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0
Apr 21 15:22:13 mb-Surface-Pro-4 upowerd[886]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-7
Apr 21 15:22:13 mb-Surface-Pro-4 gestures-restart.sh[5532]: libinput-debug-events stopped.
Apr 21 15:22:13 mb-Surface-Pro-4 gestures-restart.sh[5532]: libinput-gestures stopped.
如图所示,服务识别连接并启动脚本。然后脚本运行其 STOP 功能,但不会再次启动。我知道这可能超出了本问题的范围,但您是否看到了明显的原因?谢谢 :)
最后更新
我联系了该实用程序的开发人员。启动操作失败很可能是因为该应用程序需要在实际用户会话中运行。而不是通过系统服务运行。感谢您的时间。
答案1
方法 1:
$ cat 99-logitech-custom.rules
# Start autorun systemd .service
ACTION=="add", \
SUBSYSTEMS=="input", \
ATTR{name}=="Logitech Performance MX", \
TAG+="systemd", ENV{SYSTEMD_USER_WANTS}="logitech_custom.service"
用于udevadm control --reload && udevadm trigger
重新加载 udev。
...以及一个简单的一次性 systemd .service
$ cat ~/.config/systemd/user/logitech_custom.service
Description=Autorun actions for Logitech
[Service]
Type=oneshot
ExecStart=/opt/bin/autorun_logitech.sh
您不需要启动或启用.service。
方法 2
连接设备时,它应该在systemctl list-units
列表中可见(如果它没有显示为单元,您需要先 TAG+= 您的设备,基本上与第一种方法相同,但没有 env{systemd...})。现在,您可以使用此单元名称来udevadm info $(systemd-escape -u '<unit>' --path | sed 's/.device$//')
获取DEVLINKS=
,再次运行它systemd-escape '<devlink>' --path --suffix=device
以获取转义的 .device 名称。
$ cat ~/.config/systemd/user/logitech_custom.service
[Unit]
Description=Autorun actions for Logitech mouse
Requires=dev-input-by\x2did-usb\x2dLogitech_USB_Receiver\x2dif02\x2dmouse.device
After=dev-input-by\x2did-usb\x2dLogitech_USB_Receiver\x2dif02\x2dmouse.device
[Service]
ExecStart=/opt/bin/autorun_logitech.sh
[Install]
WantedBy=dev-input-by\x2did-usb\x2dLogitech_USB_Receiver\x2dif02\x2dmouse.device
...最后启用你的 systemd .service
$ systemctl --user enable logitech_custom.service
答案2
因此,经过相当长时间的等待,这里提出了关于如何解决此类问题的建议。
首先,你应该阅读这个帖子及其评论,因为它提供了如何设置的见解
已检测到正确的 D-Bus 消息,并相应地启动了脚本。但 libinput-gestures 仍然存在问题,因为它可以停止但无法重新启动!问题是脚本以系统身份运行重启操作。但要启动,libinput-gestures 需要用户会话,因此脚本必须由用户运行。
为此,libinput 的创建者创建了一个单独的工具。dbus 动作。由于我的操作系统不满足所需环境,我无法测试此应用程序。但我希望您可以使用它 :)