When using a systemd service to configure devices at boot time, as suggested in Automation and running at boot/Set up Linux using system, it can sometimes happen that the hardware is not ready when the service tries to start.
A blunt solution to this is to add a small delay, but a more robust alternative is to make the service unit depend on the corresponding hardware being available at the OS level.
For this it is first necessary to set up systemd to create device units with known names. This is done with udev rules, specifically with TAG+="systemd"
(to create a device unit) and a memorable SYMLINK+="<some-name>"
name.
# /etc/udev/rules.d/99-liquidctl-custom.rules
# Example udev rules to create device units for some specific liquidctl devices.
# create a dev-kraken.device for this third-generation Kraken X
ACTION=="add", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1e71", ATTRS{idProduct}=="170e", ATTRS{serial}=="<serial number>", SYMLINK+="kraken", TAG+="systemd"
# create a dev-clc120.device for this EVGA CLC
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="2433", ATTRS{idProduct}=="b200", SYMLINK+="clc120", TAG+="systemd"
Setting a custom name with SYMLINK
is optional: just with TAG+="systemd"
alone a device unit will be made available as dev-bus-usb-<bus>-<device>.device
, where the <bus>
and the <device>
numbers can be found with the lsusb
command.
The new device units can then be added as dependencies to the service unit.
# /etc/systemd/system/liquidcfg.service
[Unit]
Description=AIO startup service
Requires=dev-kraken.device
Requires=dev-clc120.device
After=dev-kraken.device
After=dev-clc120.device
...
With these changes in place, and after rebooting the system, the service should begin to wait for the devices before trying to starting.
Notes:
SUBSYSTEM
value must match how liquidctl connects to the device; devices listed by liquidctl as on a hid
bus should use the value hidraw
, while the remaining should use usb
Requires=
is used instead of Wants=
because we want a strong dependency
An alternative approach is to have systemd start the configuration service when the device is found by udev, by making the device depend on the service:
ACTION=="add", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1e71", ATTRS{idProduct}=="170e", ATTRS{serial}=="<serial number>" ENV{SYSTEMD_WANTS}="liquidcfg.service"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。