The --system bus
The systemd --system
bus is the "normal" way to use systemd. It's the system-wide bus and is run as root
. man systemd.unit
describes load paths for the --system
bus as:
/etc/systemd/system.control
/run/systemd/system.control
/run/systemd/transient
/run/systemd/generator.early
/etc/systemd/system <-- local units usually go here
/run/systemd/system
/run/systemd/generator
/usr/local/lib/systemd/system
/lib/systemd/system <-- packaged units usually go here
/run/systemd/generator.late
This man page also says:
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
Setting this variable to SYSTEMD_UNIT_PATH=/my/path/:
would add /my/path
to the front of the load paths. However, we cannot simply run this from the command line as systemd would already be running
SYSTEMD_UNIT_PATH=/my/path: systemd
To set the environment of the systemd
--system
bus, we need to look at man systemd-system.conf
. Then set values in these files to affect the system bus:
/etc/systemd/system.conf
/etc/systemd/system.conf.d/*.conf <-- Install your change here
/run/systemd/system.conf.d/*.conf
/lib/systemd/system.conf.d/*.conf
In terms of what to put in this configuration, the man page descirbes:
ManagerEnvironment=
Takes the same arguments as DefaultEnvironment=, see above. Sets
environment variables just for the manager process itself. In contrast
to user managers, these variables are not inherited by processes spawned
by the system manager, use DefaultEnvironment= for that. Note that these
variables are merged into the existing environment block. In particular,
in case of the system manager, this includes variables set by the kernel
based on the kernel command line.
Therefore install this file as /etc/systemd/system.conf.d/mypath.conf
:
[Manager]
ManagerEnvironment="SYSTEMD_UNIT_PATH=/my/path:"
Disclaimer: While SYSTEMD_UNIT_PATH
is documented in man systemd.unit
of version 250.4 on my machine, it is not documented here. That may mean that they are deprecating the feature. If SYSTEMD_UNIT_PATH
is not described in the man page of your machine, then it is not yet (or no longer) supported. In that case, the only option is to create symbolic links in /etc/systemd/system/
to each of your units in whatever location they exist.
The --user bus
The systemd --user
bus is something that runs for each user who is logged in. It's useful for user-backups, user mounts, launching GUIs, or other desktop-environment stuff like VNC servers. To manage units on this bus, you run systemctl --user {start,stop} ...
(without sudo
). man systemd.unit
describes load paths for the --user
bus as:
$XDG_CONFIG_HOME/.config/systemd/user.control
$XDG_RUNTIME_DIR/systemd/user.control
/run/systemd/transient
/run/systemd/generator.early
$XDG_CONFIG_HOME/.config/systemd/user or $HOME/.config/systemd/user
$XDG_CONFIG_DIRS/.config/systemd/user or /etc/xdg/systemd/user
/etc/systemd/user
$XDG_RUNTIME_DIR/systemd/user
/run/systemd/user
$XDG_RUNTIME_DIR/systemd/generator
$XDG_DATA_HOME/systemd/user or $HOME/.local/share/systemd/user
$XDG_DATA_DIRS/systemd/user or /usr/local/share/systemd/user
$dir/systemd/user for each $dir in $XDG_DATA_DIRS
/usr/local/lib/systemd/user/*
/usr/lib/systemd/user/*
$XDG_RUNTIME_DIR/systemd/generator.late/*
To set the environment of the systemd --user
bus, we need to look at man systemd-user.conf
. This setting values in these files to affect the user
bus:
~/.config/systemd/user.conf <-- Here if it should affect one user
/etc/systemd/user.conf
/etc/systemd/user.conf.d/*.conf <-- Here if it should affect all user buses
/run/systemd/user.conf.d/*.conf
/usr/lib/systemd/user.conf.d/*.conf
In this case, I'm not sure if we should set DefaultEnvironment=
or ManagerEnvironment=
, so I would set both.
[Manager]
ManagerEnvironment="XDG_DATA_DIRS=/my/path:/usr/share/gnome:/usr/local/share/:/usr/share/"
DefaultEnvironment="XDG_DATA_DIRS=/my/path:/usr/share/gnome:/usr/local/share/:/usr/share/"
Then you need to put your units in /my/path/systemd/user/
--system
bus (usual invocation of systemd) or are you using the--user
bus? If you are runningsudo systemctl {start,stop} foo.service
, you are running the system bus. If you are runningsystemctl --user {start,stop} foo.service
you are running the user bus.XDG_DATA_DIRS
only affects the user bus. – Stewart Apr 08 '22 at 09:27