0
votes

I wrote two udev rules which worked fine until the introduction of systemctl.

These rules run a daemon whenever a kind of USB device is plugged in and stop the same daemon when the same device is unplugged. This is done with an helper script myscript.

With systemctl the problem now is that it apparently kills the daemon invoked by myscript after some seconds the device is plugged in.

The rules are the following:

  • SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{VID_PID}="%s{idVendor}:%s{idProduct}", ACTION=="add", RUN+="/etc/init.d/myscript plug %E{VID_PID}"`

  • SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", ENV{VID_PID}="%E{ID_VENDOR_ID}:%E{ID_MODEL_ID}", RUN+="/etc/init.d/myscript unplug %E{VID_PID}"`

Note that the myscript accepts two arguments: the action plug or unplug and the device identifiers.

Do you know how to fix the problem or how to implement the same - if necessary - in terms of systemctl?

1

1 Answers

0
votes

As the systemd.device man page says, write a unit file for your service, and then tag the device with "systemd" and then use the SYSTEMD_WANTS property to start the unit. Do not use the RUN property for long-running processes.