usb_modeswitch
package usually comes with ready udev rules for automatic modem mode switching. ppp
, independently of it, besides itself, includes a service for demonization. These configurations are independent of each other.
If you use them at the same time, a conflict may arise : pppd
starts before udev switches the usb_modeswitch -J
-J.
You can leave Restart=on-failure
with RestartSec=5s
, but is it sports?
To begin, edit usb_modeswitch.conf - DisableSwitching=yes
. This file is implicitly used by the "default" rules - they will not be useful to us, although they will not interfere.
Now - systemctl disable ppp@….service
. We will not need to multi-user.target
unit from multi-user.target
; [Install]
no longer useful.
It remains to make it all work again - in a different way.
The new udev rule is intended to solve the problem posed earlier: it must first communicate the usb_modeswitch
task, and only then turn to systemd.
In the USB subsystem, a device can be defined with two attributes-identifiers: idVendor
and idProduct
. They can be seen lsusb-ohm - they are located respectively after the "ID".
This almost corresponds to the first line of the new configuration:
$ su - $ cd /etc/udev/rules.d $ cat > 20-provider-modem.rules <<< …
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="…", ATTR{idProduct}=="…", RUN+="/usr/sbin/usb_modeswitch -v $attr{idVendor} -p $attr{idProduct} -J"
- it is not necessary to specify the number system ( 0x
).
Now we turn to the consideration of another subsystem - now ttyUSB0
important for us. Again, turn to your favorite text editor:
$ cat >> 20-provider-modem.rules <<< …
SUBSYSTEM=="tty", KERNEL=="ttyUSB0", TAG+="systemd", ENV{SYSTEMD_WANTS}="ppp@provider.service"
- here udev informs systemd at the appropriate time about the possibility of running ppp@
.
Finally:
$ udevadm control --reload
I was once very interested in the intelfx conclusion about the relationship between systemd and udev :
udev and systemd are awesome powerful frameworks that complement each other.
systemd is based on dependency model: execute X if Y is available.
udev - on the event model: when Y becomes available, execute X.
The connection of userspace with kernel is really underlined very expressively, and this can not fail to impress. The example shown — perhaps a little promising or mediocre — wholly reveals the potential of this tool.
Source: https://habr.com/ru/post/311268/
All Articles