Systemd 没有设置 RUNTIME_DIRECTORY 环境?

Systemd not setting RUNTIME_DIRECTORY env when it should?

我有一个非常简单的测试服务。 最终我将成为 运行 一个 node 守护程序,但现在用 env 调试这个问题...

$ systemctl cat http-endpoints
# /etc/systemd/system/http-endpoints.service
[Unit]
Description=HTTP endpoints for triggering events
After=network.target

[Service]
Type=simple
;PassEnvironment=RUNTIME_DIRECTORY
RuntimeDirectory=endpoints
Environment=TEST=asdf
ExecStart=/usr/bin/env

[Install]
WantedBy=default.target

我正在尝试使用 systemd 的 RuntimeDirectory= 功能。 我期待环境变量 RUNTIME_DIRECTORY.

尚未设置。

systemd[1]: Started HTTP endpoints for triggering events.
env[26794]: LANG=en_US.UTF-8
env[26794]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
env[26794]: INVOCATION_ID=fb24db240f454722b847ab7cefd5eb59
env[26794]: JOURNAL_STREAM=9:8063338
env[26794]: TEST=asdf

我已经尝试了一些东西。

如果我手动设置它,Environment=RUNTIME_DIRECTORY=/run/endpoints,它会起作用。 但是那个配置应该不是必需的。

/run/endpoints 目录已按预期创建(并立即删除,因为 env 退出,但这不是问题所在)。

$ systemd --version
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid

Ubuntu 18.04.3 没有最新的 systemd。

在 v240 中添加了对环境变量的支持。

CHANGES WITH 240:
    * When the RuntimeDirectory=, StateDirectory=, CacheDirectory=,
      LogsDirectory=, ConfigurationDirectory= settings are used in a
      service the executed processes will now receive a set of environment
      variables containing the full paths of these directories.
      Specifically, RUNTIME_DIRECTORY=, STATE_DIRECTORY, CACHE_DIRECTORY,
      LOGS_DIRECTORY, CONFIGURATION_DIRECTORY are now set if these options
      are used. Note that these options may be used multiple times per
      service in which case the resulting paths will be concatenated and
      separated by colons.

我希望这可以节省一些人我花在解决这个问题上的时间。