gpt4 book ai didi

linux - systemd 脚本 - 由 ExecStartPre 更新的环境文件

转载 作者:太空狗 更新时间:2023-10-29 11:17:32 24 4
gpt4 key购买 nike

我正在 Docker 环境中试用 systemd 脚本。

考虑一下:

ExecStartPre 中提到的命令更新环境文件,而 ExecStart 实际上使用了 env 中提到的环境变量。文件。?(都在同一个 systemd 文件中)。

像这样:

[Unit]
Description=test service
Before=memcached.service

[Service]
Type=oneshot
EnvironmentFile=-/etc/sysconfig/testfile
ExecStartPre=/usr/local/bin/update_sysconfig_testfile.sh
ExecStart=/usr/bin/testmebinary $VOLUMES

[Install]
WantedBy=multi-user.target

这里,$VOLUMES 在测试文件中定义,并由update_sysconfig_testfile.sh 脚本。

systemd 是否会知道 ExecStartPre 所做的更改(或)它只是加载测试文件中的任何值?

如果有更好的方法,请分享。

最佳答案

作为替代方法,考虑使用类似 with_testfile_vars 的脚本执行以下操作:

#!/bin/sh
export foo=bar # export the same calculated values you would otherwise write to the file
export baz=qux
exec "$@" # then invoke your "real" program

...使用该包装器的服务文件:

[Unit]
Description=test service
Before=memcached.service

[Service]
Type=oneshot
ExecStart=/usr/local/with_testfile_vars /usr/bin/testmebinary $VOLUMES

[Install]
WantedBy=multi-user.target

根本不需要 EnvironmentFile,没有关于它的解释方式的顺序依赖性,不用担心 systemd 的解析与 shell 的解析有何不同,等等。

关于linux - systemd 脚本 - 由 ExecStartPre 更新的环境文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42835750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com