I moved most of my biggest files to a removable disk, some of these files are also torrents that I would like to seed. I use deluged as my torrent client which is started by systemd on my user. Now, the drive may be plugged at boot time or mounted at later date, which of course causes deluged to be confused and complain that the files are a mismatch. The most naive solution is to only start deluged service after the device is mounted and that's what I plan to do.I've seen these answers which suggest using RequiresMountsFor and according to systemctl --user show deluged seems to do what I want:After=basic.target -.slice home.mount network-online.target media-braiam-AA64B45RequiresMountsFor=/media/braiam/AA64B45A64B42AC9 /home/braiamNow, that allows the unit to be started if I have mounted the device, but it doesn't stops the unit when the device is being unmounted, nor seems to start the service when the device is being mounted.In summary:The service starts only if the device is mounted or can be mountedThe service will stop if the device is being unmountedThe service will start if the device is mountedThe device will stay mounted if the service is stopped.This is what I've managed:[Unit]Description=Deluge Bittorrent Client DaemonAfter=network-online.targetRequiresMountsFor=/media/braiam/id/BindsTo=media-braiam-id.mountFor now, this stops the service when it's being unmounted, starts only if the mount point can be mounted and tries to mount the device. It won't mount the device, since only root can mount it (I think if I install a unit for the system, this will be possible). It doesn't start if the mount point becomes available, however. How do I achieve what I want?
Start/stop a user unit whenever a device has been mounted/unmounted
systemd