0

This might be a mostly aesthetic problem, but it's been bugging me enough to put a little more effort into resolving it.

In my work environment, we rely very heavily on in-house developed software for Linux workstations and servers, and I've spent some time working on some build tools that provide a consistent build and install process, and reduce per-project boilerplate. I've tried to adhere to existing standards as much as I can. What I have as a result is an install system that puts output files in /usr/local when installing directly from source, and in /usr when packaging (eg. building RPMs). Most of our software is currently installed directly from source, though this will likely change in the future.

So when installing directly, executables go in /usr/local/bin and /usr/local/libexec, libraries in /usr/local/lib64 (this is a RHEL environment), include files in /usr/local/include, and so forth. This works for nearly everything -- .desktop files, icons, pkg-config files, documentation, configuration files, ... it either Just Works or can be easily configured to work, with simple system changes. But I haven't had success with systemd unit files.

My build tools currently place these files in /usr/lib/systemd/system, which is therefore a hard-coded exception to the normal behavior.

Is there a way to configure systemd to also look for service unit files under /usr/local (ie. /usr/local/lib/systemd/system), so the install process can be more consistent, I can avoid the install-time warnings about non-portable hard-coded install target directories, and the files could go to what seems like a more canonically 'correct' location? I'm okay with adding configuration to the system (ideally in the form of drop-ins) to get this to work.

We don't do this much here, but I suppose this question might also apply to software installed to a custom prefix, eg. /opt/MySoftware.

  • I don´t think this is possible. I believe the systemd path is defined during compilation. You can find more details in the [Systemd man page](https://manpages.ubuntu.com/manpages/focal/en/man5/systemd.unit.5.html): **Unit files are loaded from a set of paths determined during compilation** – LincolnP May 05 '23 at 18:10
  • 1
    @LincolnP Interesting! I see on that page, under Unit File Load Path, Table 1, that `/usr/local/lib/systemd/system` is indeed listed. I wonder if it's a bug on my system, or maybe my version of systemd on RHEL 8 is too old... – Chris Robison May 05 '23 at 18:48
  • 1
    You can use `systemd-analyze unit-paths` to check where your systemd looks for unit files. – Ginnungagap May 06 '23 at 05:58

0 Answers0