10

I want to change how a custom systemd service works.

systemctl edit serviceName

This edits /etc/systemd/system/serviceName.d/override.conf file. Override.conf is called a drop-in file and serviceName.d/ is a drop-in directory. I want to put a drop-in file definition and drop-in folder definition on the internet.

Paku
  • 455
  • 1
  • 4
  • 15
  • systemd has such huge documentation. [systemd.unit](https://www.freedesktop.org/software/systemd/man/systemd.unit.html) Did you try searching for explanation yourself? What did you find? – KamilCuk Jan 21 '20 at 14:02
  • I would define: drop-in file - a file named (*.conf) which is contained in a drop-in directory and the contents of which are concatenated to the (service) unit file with the same name as the drop-in directory. – Paku Jan 21 '20 at 14:12
  • Great. The filename must end with `.conf` suffix. And there is a whole, like, order in which drop-in directories are read and the whole naming scheme .of drop-in directories – KamilCuk Jan 21 '20 at 14:16
  • 3
    IMO, this question is good for people who are googling about drop-in files or systemd. KamilCuk also provided the link to the very good documentation. As such, if opening the question would improve its' visibility, then i argue for opening of this question. – Paku Jan 28 '21 at 12:08

1 Answers1

8

I would define: drop-in file - a file ending with .conf suffix, which is contained in a drop-in directory and the contents of which are concatenated to the (service) unit file with the same name as the drop-in directory.

Writing into override.conf for example After=memcached.service will add "memcached.service" to the list of elements in the After command in the unit file. If we want to override the After command, then we need to first reset the command withAfter= and then add our commands.

override.conf should be eg:

[UNIT] 
After= 
After=remote-fs.target sqldb.service memcached.service
Paku
  • 455
  • 1
  • 4
  • 15
  • 1
    Actually, you can't reset a dependency such as After (or Before). If you need to delete and entry from those, you will need to create a new service file under /etc/systemd/system/. See “[Example 2. Overriding vendor settings](https://www.freedesktop.org/software/systemd/man/systemd.unit.html#id-1.14.3)” in the systemd.unit documentation for details. – Doyle B Mar 23 '23 at 17:36
  • 1
    The concept of drop-in config files (and directories) predates `systemd` by _decades_, possibly started with SysV's `init.d` boot files, and it's also used by `grub`, `apt`, `apache` and so many other (and older) software. I would not include the `.conf` suffix in a _definition_, as that depends on each software: `apt`, for example, uses `.list`. One thing most (but not _all_) have in common is that their config drop-in _directory_ ends with `.d/` – MestreLion Jun 06 '23 at 05:30