19

I have a Debian stretch where I'm running transmission-daemon as a service.

I keep my seeded files on an external USB hard disk drive mounted on /mnt/external-disk. This disk has an ext4 filesystem, and I mapped it in /etc/fstab by uuid.

The problem is:

When the service transmission-daemon starts at boot it doesn't check if the external filesystem is already mounted so it doesn't find the files on it, and I get a data error and the torrent files are not seeded, but the service starts.

To resolve this problem I checked the systemd documentation, and I found what was missing:

The line RequiresMountsFor= in the [Unit] section of the transmission-daemon.service file is located in the tree below /lib/systemd/. After I added that line with the path of the mountpoint /mnt/external-disk the problem disappeared and the service was working fine. If I rebooted the machine, the service was working, and the files were seeded.

This worked until I had a apt-get dist-upgrade where the package transmission-daemon was involved and after it stopped. So I checked the transmission-daemon.service, and I found the modification I made was missing.

I added the line RequiresMountsFor= another time with the proper path, and the problem was fixed again.

My question is: How can I make this modification persistent?

0

2 Answers 2

27

You should override the unit with a unit in /etc. The easiest way to do this is to use systemctl edit:

sudo systemctl edit transmission-daemon

will open an editor and allow you to create an override snippet.

An override snippet ensures that future changes to the package’s unit (in /lib) are taken into account: the reference will be the package’s unit, with your overrides applied on top. All you need to use this in your case is a .conf file in /etc/systemd/system/transmission-daemon.service.d/, containing only the section and the RequiresMountsFor line. systemctl edit will do this for you, creating an override.conf file in the appropriate location.

Alternatively, you can copy the full /lib/systemd/system/transmission-daemon.service unit to /etc/systemd/system and edit that. Again, systemctl edit can take care of this for you, with the --full option.

Look for “Example 2. Overriding vendor settings” in the systemd.unit documentation for details.

0
4

Copy it to /etc/systemd (or an appropriate sub-directory of /etc/systemd) and modify the copy.

/lib/systemd is for packaged unit files. They will get overwritten when systemd (or whatever package provides them) is upgraded.

/etc/systemd is for your own and for customised unit files. Unit files you place in here will override the package-provided file and will not be replaced on upgrade.

1
  • 2
    Don't do that. If the service file changes in a package upgrade the copy will override those changes. Use an override file per Stephen Kitt's answer. Commented Jan 22, 2018 at 18:59

Not the answer you're looking for? Browse other questions tagged .