# udev

## Start (and stop) a systemd daemon

Create a udev rule to start the daemon:
```
% cat /etc/udev/rules.d/10-bluetooth-service.rules 
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0a5c", ATTRS{idProduct}=="21e8", TAG+="systemd", ENV{SYSTEMD_WANTS}="bluetooth.service"
```
This one starts the bluetooth systemd service when a specific usb bluetooth dongle is added to the system.

If you need to find `idVendor` and `idProduct` you can start `udevadm monitor --property` while plugging the usb device in and out.

To stop the daemon again you need to edit the systemd service file of the daemon - in this case `systemctl edit bluetooth.service`:
```
[Unit]
BindsTo=sys-subsystem-bluetooth-devices-hci0.device
After=sys-subsystem-bluetooth-devices-hci0.device
```
The device name in this case is found by `systemctl list-units --all --full | grep "\.device"`.
