我正在运行Ubuntu 18.4,我遇到了一个脚本问题,该脚本在udev rule触发时拒绝运行。
这是情况:我在 Surface Pro 4 上运行。该设备有一个可拆卸的键盘。我运行一个名为libinput-gestures的软件。每当键盘分离并重新连接时,手势将不起作用。手动修复很容易:
libinput-gestures-setup restart
所以我尝试运行的脚本正是这样做的。这是它的全部荣耀:
#!/bin/sh
libinput-gestures-setup restart
我想在 udev 规则的add事件上运行它。这是 .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 时,我必须将我的用户添加到组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.
如图所示,服务识别连接并启动脚本。脚本然后运行它的停止功能,但它不会再次启动。我知道这可能超出了此问题的范围,但您是否看到明显的原因?谢谢 :)
最后更新
我联系了该实用程序的开发人员。启动操作很可能会失败,因为应用程序需要在实际的用户会话中运行。不是通过系统服务。谢谢你的时间。