Usar RUN+=
é a abordagem errada. Como man udev
deixa claro:
This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device.
Starting daemons or other long running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.
A abordagem correta é usar SYSTEMD_WANTS
(de man systemd.device
):
THE UDEV DATABASE The settings of device units may either be configured via unit files, or directly from the udev database (which is recommended). The following udev properties are understood by systemd:
SYSTEMD_WANTS= Adds dependencies of type Wants from this unit to all listed units. This may be used to activate arbitrary units, when a specific device becomes available. Note that this and the other tags are not taken into account unless the device is tagged with the "systemd" string in the udev database, because otherwise the device is not exposed as systemd unit.
Você só precisa de um arquivo de serviço em /etc/systemd/system/media-USBDRIVE.mount.wants/
:
[Unit]
Description=Backup files to USBDRIVE
Requires=media-USBDRIVE.mount
After=media-USBDRIVE.mount
[Service]
ExecStart=/path/to/backupscript
[Install]
WantedBy=media-USBDRIVE.mount
Nota: isso pressupõe que seu drive USB se chame USBDRIVE e esteja montado em /media/USBDRIVE
.