9

This question already has an answer here:

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?

marked as duplicate by don_crissti, Stephen Kitt, Wouter Verhelst, Rui F Ribeiro, jayhendren Jan 22 '18 at 20:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

16

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 a 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 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.

  • Hmm, on OpenSUSE, after doing the override and interacting with "service" to restart or ask for status, I get "Warning: mariadb.service changed on disk. Run 'systemctl daemon-reload' to reload units." However, running that command doesn't seem to do anything, and my override doesn't seem to apply. – Artem Russakovskii Jan 12 at 23:49
  • Turned out to be some sort of a bug/confusion because of aliased services (mysql aliased to mariadb). I was modifying mysql and was running into these issues, but once I modified mariadb, the changed stuck, and no more warnings. – Artem Russakovskii Jan 13 at 0:03
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
    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. – John Kugelman Jan 22 '18 at 18:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.