1.2 KiB
1.2 KiB
Solution
First alternative solution
The udev rule
➜ ~ git:(master) ✗ cat /etc/udev/rules.d/99-backup_to_usb_stick.rules
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="2469ffe5-e066-476d-805a-cde85a58ea3b", ACTION=="add", TAG+="systemd", SYMLINK+="backup_partition"
➜ ~ git:(master) ✗
The device file
➜ ~ git:(master) ✗ cat /etc/systemd/system/dev-backup_partition.device
[Unit]
Description=my device
Wants=tester.service
➜ ~ git:(master) ✗
The service file
➜ ~ git:(master) ✗ cat /etc/systemd/system/tester.service
[Unit]
Description=A tester
Requires=dev-backup_partition.device
After=dev-backup_partition.device
[Service]
ExecStart=echo "test"
[Install]
WantedBy=default.target
➜ ~ git:(master) ✗
Second alternative solution
Can be done via mount files as well.
The udev rule
➜ ~ git:(master) ✗ cat /etc/udev/rules.d/99-backup_to_usb_stick.rules
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="2469ffe5-e066-476d-805a-cde85a58ea3b", ACTION=="add", TAG+="systemd", SYMLINK+="backup_partition", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media/backup_stick"
➜ ~ git:(master) ✗