dirs-rs
dirs-rs copied to clipboard
Systemd Service Directories
systemd gives users the option in service units to create and point to various directories under paths like, /run/{app}, /var/lib/{app}, etc. Would It make sense to add these environment variables as possible returns if the XDG paths don't match? I guess I'm asking if I implement this, would you accept such a PR?
systemd.exec(5) has this table that seems to layout the variables set and roughly where they'd end up. I'm not sure why some of these paths would fall into the XDG_CONFIG_HOME paths if the service is a user service. I'd think XDG_DATA_HOME makes more sense.
Table 2. Automatic directory creation and environment variables
┌────────────────────────┬────────────────┬───────────────────────┬──────────────────────────┐
│Directory │ Below path for │ Below path for │ Environment │
│ │ system units │ user units │ variable set │
├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
│RuntimeDirectory= │ /run/ │ $XDG_RUNTIME_DIR │ $RUNTIME_DIRECTORY │
├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
│StateDirectory= │ /var/lib/ │ $XDG_CONFIG_HOME │ $STATE_DIRECTORY │
├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
│CacheDirectory= │ /var/cache/ │ $XDG_CACHE_HOME │ $CACHE_DIRECTORY │
├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
│LogsDirectory= │ /var/log/ │ $XDG_CONFIG_HOME/log/ │ $LOGS_DIRECTORY │
├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
│ConfigurationDirectory= │ /etc/ │ $XDG_CONFIG_HOME │ $CONFIGURATION_DIRECTORY │
└────────────────────────┴────────────────┴───────────────────────┴──────────────────────────┘
I do not think that this change would make sense. This addition would be objectively useful, but, in my opinion, applications should be architectured in such a way, where non-standard (i.e non-XDG) paths should be provided to the application by systemd, via generated config, or command-line argument, if required.
systemd should not be a target for any piece of software, since it already has more than enough features to adapt to anything.
I've created the systemd-directories crate for this.