【问题标题】:Systemd not setting RUNTIME_DIRECTORY env when it should? [closed]Systemd 什么时候没有设置 RUNTIME_DIRECTORY 环境? [关闭]
【发布时间】:2020-05-12 14:35:33
【问题描述】:

我有一个非常简单的测试服务。 最终我会运行一个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

【问题讨论】:

    标签: environment-variables systemd


    【解决方案1】:

    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.
    

    我希望这可以节省我试图弄清楚这一点的时间。

    【讨论】:

    • 在 Debian 10 上使用 systemd 241 时遇到同样的问题。非常奇怪的选择来打包手册页,其中记录了仅在 future 版本中实际存在的功能。
    猜你喜欢
    • 1970-01-01
    • 2016-05-28
    • 2016-01-21
    • 1970-01-01
    • 2019-06-22
    • 2019-11-21
    • 1970-01-01
    • 2010-10-17
    相关资源
    最近更新 更多