如何为多个进程重用主管进程的环境定义

发布于 2025-01-10 13:05:56 字数 272 浏览 0 评论 0原文

我定义了多个主管程序,并且它们都定义了相同的环境变量,现在我需要添加一个新的,并且必须将其添加到每个程序部分。有没有办法定义一个对整个主管配置文件有效并且我可以重用的环境变量?例如 /etc/supervisor/conf.d/foo.conf 下的文件:

my_env=foo=2,bar="hi",zee="ok"

[program:foo]
environment=my_env

[program:bar]
environment=my_env

I have multiple supervisor programs defined and they all have the same environment variables defined, now I needed to add a new one and I had to add it to each program section. Is there a way to define a environment variable which is valid for the whole supervisor config file and which I could reuse? E.g file under /etc/supervisor/conf.d/foo.conf:

my_env=foo=2,bar="hi",zee="ok"

[program:foo]
environment=my_env

[program:bar]
environment=my_env

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2025-01-17 13:05:56

是的,这是可能的。您可以将自定义环境键值添加到 Supervisord 部分,位于环境键。

环境

格式为 KEY="val",KEY2="val2" 的键/值对列表,将放置在所有子进程的环境中。这不会改变supervisord本身的环境。此选项可以包含值 %(here)s,该值扩展为在其中找到supervisord 配置文件的目录。包含非字母数字字符的值应加引号(例如 KEY="val:123",KEY2="val,456")。否则,引用这些值是可选的,但建议这样做。要转义百分比字符,只需使用两个即可。 (例如 URI="/first%%20name") 请注意,子进程将继承用于启动supervisord 的shell 的环境变量,但此处和程序环境选项中覆盖的变量除外。请参阅子进程环境。

由于您有多个正在运行的管理程序,我相信您需要在每个 .conf 文件的 [supervisord] 部分中指定此环境键值对。

编辑:为了澄清OP在评论中的混乱,[supervisord]部分与[program]部分不同。

Yes, that's possible. You may add your custom environment key-values into the Supervisord section, below the environment key.

environment

A list of key/value pairs in the form KEY="val",KEY2="val2" that will be placed in the environment of all child processes. This does not change the environment of supervisord itself. This option can include the value %(here)s, which expands to the directory in which the supervisord configuration file was found. Values containing non-alphanumeric characters should be quoted (e.g. KEY="val:123",KEY2="val,456"). Otherwise, quoting the values is optional but recommended. To escape percent characters, simply use two. (e.g. URI="/first%%20name") Note that subprocesses will inherit the environment variables of the shell used to start supervisord except for the ones overridden here and within the program’s environment option. See Subprocess Environment.

Since you have multiple supervisor programs running, I believe you will need to specify this environment key-value pairs in the [supervisord] section of each .conf file.

Edit: To clarify OP's confusion in comments, [supervisord] section is different from a [program] section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文