Last active
October 21, 2023 08:29
-
-
Save jakob-hede/3fa0eb8c38e718536afd328ffab1becc to your computer and use it in GitHub Desktop.
SYSTEMD_UNIT_PATH | How to provide *additional* search paths for systemd unit files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SYSTEMD_UNIT_PATH note 2023.10.21 | |
How to provide *additional* search paths for systemd unit files. | |
---------------------------------------------------------------- | |
SYSTEMD_UNIT_PATH can be used to provide additional search paths for systemd unit files - IF the variable ends with a colon. | |
SYSTEMD_UNIT_PATH MUST be available before systemd is started. | |
So the only way I have found to do this is to set it as "kernel parameters". | |
I have so far made it work in 3 contexts: | |
1. In hardware via GRUB | |
2. In LXD | |
3. In a Proxmox container | |
---------------------------------------------------------------- | |
First make the custom directory: | |
(root user is assumed for all operations) | |
In my case: | |
mkdir /opt/system.custom | |
---------------------------------------------------------------- | |
1. In hardware via GRUB | |
1.1. Edit /etc/default/grub | |
Add the following line: | |
GRUB_CMDLINE_LINUX="<other stuff> SYSTEMD_UNIT_PATH='/opt/system.custom:'" | |
Save the file. | |
1.2. Update GRUB | |
-[debian] update-grub | |
-[RHEL] grub2-mkconfig -o /boot/grub2/grub.cfg | |
reboot | |
Or if grub2-mkconfig is not desirable, edit directly | |
/boot/grub2/grub.cfg: | |
set kernelopts="<other stuff> SYSTEMD_UNIT_PATH='/opt/sofa/system.custom:'" | |
---------------------------------------------------------------- | |
2. In LXD | |
lxc config edit <name eg. debsid> | |
config: | |
environment.SYSTEMD_UNIT_PATH: '/opt/system.custom:' | |
---------------------------------------------------------------- | |
3. In a Proxmox container | |
Edit the container config file: | |
eg: /etc/pve/nodes/blambox/lxc/12002005.conf | |
Add the following line: | |
lxc.environment: SYSTEMD_UNIT_PATH=/opt/system.custom: | |
---------------------------------------------------------------- | |
To test that the custom search path is in effect, run: | |
systemctl show --property=UnitPath | |
I also put a dummy unit-file "aabbcc.service" in /opt/system.custom | |
Then I ran: | |
systemctl daemon-reload OR rebooted | |
systemctl cat aabbcc.service | |
---------------------------------------------------------------- | |
Documentation: | |
https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Unit%20File%20Load%20Path | |
Unit File Load Path | |
Unit files are loaded from a set of paths determined during compilation, described in the two tables below. Unit files found in directories listed earlier override files with the same name in directories lower in the list. | |
When the variable $SYSTEMD_UNIT_PATH is set, the contents of this variable overrides the unit load path. If $SYSTEMD_UNIT_PATH ends with an empty component (":"), the usual unit load path will be appended to the contents of the variable. | |
---------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment