How Modify Systemd Unit Files Right Way

How Modify Systemd Unit Files Right Way

Location of systemd unit files

  • /lib/systemd/system - The system's copy of unit files are generally kept in this directory. When software installs unit files on the system, this is the location where they are placed by default.

  • /run/systemd/system - Systemd unit files created at run time. This directory takes precedence over the directory with installed service unit files.

  • /etc/systemd/system/ - If you wish to modify the way that a unit functions, the best location to do so is within this directory. Unit files found in this directory location take precedence over any of the other locations on the filesystem. If you need to modify the system's copy of a unit file, putting a replacement in this directory is the safest and most flexible way to do this.

How edit systemd unit files

You have two options:

Extending the default unit configuration

You can alter or add specific configuration settings for a unit, without having to modify unit files by creating .conf files in a drop-in directory /etc/systemd/system/..d/
i.e. create a /etc/systemd/system/pimd.service.d/restart.conf

Overridding the default unit configuration

Copy the unit file from /lib/systemd/system/ to /etc/systemd/system/. And then make your modifications in /etc/systemd/system/name.service to completely override the unit file(s) supplied by the package maintainer.