3 ms·
Is BindsTo= the right way to have systemd shut the service down if the device disappears?
by yrro 4y ago
Is BindsTo= the right way to have systemd shut the service down if the device disappears?
- evgpbfhnr 4y agoIt's been a while but yes BindsTo is a good idea if you can express the device in a reliable way. Unfortunately for USB devices the path will look like something that depends on the USB port it's been plugged in (I only have a sound card on my hands, but something like these two alternatives on two different ports): sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d4-1\x2d4:1.0-sound-card1-controlC1.device sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d1-1\x2d1:1.0-sound-card1-controlC1.device notice the usb-`1-1:4` became `1-1:1` That makes BindsTo unpractical unless you're sure you'll always plug in the camera on the same port everytime, so it might not be best. This made me look up how I'd do this if the needs arise, so I haven't tried, but `StopWhenUnneeded=true` in the service definition looks like it would stop it properly when the device "wanting" it is gone? cf. https://unix.stackexchange.com/questions/528803/systemd-doesnt-stop-the-service-when-the-device-is-removed https://unix.stackexchange.com/questions/528803/systemd-does... I learned something new :)