S
S
S-trace2021-03-31 18:47:15
linux
S-trace, 2021-03-31 18:47:15

Systemd: removable drives - automount and start services - how to do?

Hello.

Tell me how to beautifully make the following script on systemd:
1. USB HDD is connected to the system.
2. systemd mounts its partitions by partition UUIDs.
3. After mounting a certain partition (which corresponds to a given mount point, for example mnt-backups.mount), a certain service (for example, rsync.service) is started.

I know that in order for the rsync.service service to stop when /mnt/backups/ is unmounted, you need to execute systemctl edit rsync.service and enter the following into it:

[Unit]
BindsTo=mnt-backups.mount

The question is how to achieve the opposite effect (so that rsync.service is automatically started when /mnt/backups/ is mounted)?

Also, the question is, how do I get systemd to automatically mount a USB-HDD when I plug it in?
I know that it is possible to write a UDEV rule in /etc/udev/rules.d/99-usb_hdd.rules that will mount the USB HDD according to its properties after connecting via the good old mount /mnt/backup/ provided that in /etc/fstab has an entry to mount this partition by UUID, but this is not a systemd solution.

Is there a nice systemd-style way to solve this kind of problem?

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xotkot, 2021-03-31
@xotkot

The question is how to achieve the opposite effect (so that rsync.service is automatically started when /mnt/backups/ is mounted)?

RequiresMountsFor

P
Puma Thailand, 2021-04-01
@opium

And what for, make backups over the rsincom network simply

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question