Systemd Default Working Directory
For when you forget to configure WorkingDirectory
The default working directory for a systemd service is relative to the root of the system running the service manager. This is likely /
. The default working directory is used when WorkingDirectory=
is not set in the service configuration file, *.service
.
Avoiding caring about the working directory
If you are here it is likely because a service generated or opens files relative to the working directory instead of absolute paths.
By using absolute paths to resources, the working directory won’t matter.
The recommended location for service files such as SQLite databases that are not user specific is in /opt/<service_name>
. If settings are user specific, try putting them in ~/.config/<service_name>
.
For development of the service sometimes it is convenient to reference resources by relative paths. Try using guards like NDEBUG
in C and C++ or __debug__
in python to use relative paths at development time and absolute paths in production. Be sure to test!!