5

At startup, usb-modeswitch automatically switches the dongle to modem mode and the device shows itself as 12d1:1506. After this, a script should run, connecting to the Internet. I am not sure about using /etc/rc.local since Arch has moved to pure systemd. How to I express this dependency (run a script only after the device has switched) in systemd terms?

udev rules cannot run long scripts, and mine is.

don_crissti
  • 79,330
  • 30
  • 216
  • 245
Moshanator
  • 153
  • 1
  • 4

1 Answers1

4

The recommended approach would be to have udev start a systemd service, which itself depends on your device.

The service file should look something similar to the following:

my.service - to be placed in /etc/systemd/system

[Unit]
Description=<DESCRIPTION HERE>
BindsTo=<DEVICE UNIT HERE>.device
After=<DEVICE UNIT HERE>.device

[Service]
ExecStart=<CALL TO SCRIPT HERE>

Note: to get a list of the available device units use

list-units --all --full | grep ".device"

And the udev rule should be something like the following:

90-my.rules - to be placed in /etc/udev/rules.d

KERNEL=="tty*", ATTRS{serial}=="<DEVICE SERIAL HERE>", TAG+="systemd", ENV{SYSTEMD_WANTS}="my.service"

Note: to get a list of the attributes of your specific device, including its serial number, use

udevadm info -a -n /dev/tty*

This question, though fairly different, might also be of interest.

brunocodutra
  • 556
  • 5
  • 14