Modify existing unit files

To customize and optimize services without creating a new configuration from scratch, you can modify an existing unit file. If you want to modify existing unit files, proceed to the /etc/systemd/system/ directory.

Before you begin

  • You have administrative privileges.

About this task

Do not modify the unit files in the /usr/lib/systemd/system/ directory.

Procedure

  • Create a directory for supplementary configuration files at /etc/systemd/system/<unit>.d/. You can extend the default configuration with additional functionality, while still referring to the original unit file. Changes to the default unit introduced with a package upgrade are therefore applied automatically. For details, see extending the default unit configuration.
  • Create a copy of the original unit file from /usr/lib/systemd/system/ directory in the /etc/systemd/system/ directory and make changes there. The copy overrides the original file, therefore changes introduced with the package update are not applied. This method is useful for making significant unit changes that should persist regardless of package updates. For details, see Overriding the default unit configuration.
    1. To return to the default configuration of the unit, delete custom-created configuration files and the /etc/systemd/system/<unit>.d/ drop-in directory.
    2. Apply changes to unit files:
      # systemctl daemon-reload

      The daemon-reload option reloads all unit files and recreates the entire dependency tree, which is needed to immediately apply any change to a unit file.

    3. If the modified unit file belongs to a running service, restart the service:
      # systemctl restart <name>.service
      Important

      To modify a service properties, such as dependencies or timeouts, that is handled by a SysV initscript, do not modify the initscript. Instead, create a systemd drop-in configuration file for the service. For details, see extending the default unit configuration and overriding the default unit configuration.

      To manage the service in the same way as a normal systemd service, create a new directory /etc/systemd/system/network.service.d/ and a systemd drop-in file /etc/systemd/system/network.service.d/<example_config.conf>. Then, put the modified values into the drop-in file.

      The systemd service identifies the network service as network.service, so the created directory must be named as network.service.d.