Centos – Common location for systemd unit files on Ubuntu and RHEL

centosrhelsystemdUbuntu

I would like to create a scripted install for a list of Systemd services. This installation should support both Ubuntu (starting with version 16.04) and RHEL/CentOS (starting with version 7.2)

I read RHEL docs and found three paths that I could store unit files in, these paths are:

  • /usr/lib/systemd/system/
  • /lib/systemd/system/
  • /etc/systemd/system

What is the correct location for services that fulfills these criteria:

  • Unit files are there for non-system level services (application specific services)
  • No already existing OS level services are overwritten
  • The location is identical on Ubuntu and RHEL/CentOS

Best Answer

In default Red Hat distributions, /lib is a symlink to /usr/lib, but it appears those are different locations in Ubuntu.

According to the systemd documentation, /usr/lib/systemd/system/ is designated to hold upstream unit files that would not be edited by users and instead be provided and updated via packages.

The /etc/systemd/system is designated as where user provided unit files would be. Packages should not override or update anything in /etc/systemd/system. You can also use /etc/systemd/system to override existing unit files.

So using /etc/systemd/system should be the most compatible between different distributions.

Related Question