Modify Systemd Unit File Without Altering Upstream Unit File

systemd

I have installed the pimd service by means of apt. This comes with an upstream systemd unit file (/lib/systemd/system/pimd.service).

I want the service to be restarted when for some reason it gets killed, hence I wish to add the line Restart = always in the unit file.

However, I don’t want to modify the upstream unit file.

Is there any workaround for this?

Best Answer

You have two options:

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

    The command systemctl edit --full <service-name> automates this for you.

  • 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/<unit-name>.<unit-type>.d/
    i.e. create a /etc/systemd/system/pimd.service.d/restart.conf

    The command systemctl edit <service-name> performs these steps for you.

See man systemd.unit