Yocto:systemd:在配方中设置 systemd 环境变量
Yocto: systemd: set systemd environment variable in recipe
是否可以从配方中设置 systemd 环境变量以在目标上执行与 'systemctl set-environment SOME_ENV_VAR' 相同的操作?
您的食谱可以安装 systemd.conf.d file to set the DefaultEnvironment
选项,例如
customrecipe/files/defaultenv.conf
[Manager]
DefaultEnvironment=CUSTOMENV=42
customrecipe/customrecipe.bb
SUMMARY = "Example Recipe"
LICENSE = "CLOSED"
SRC_URI = "file://defaultenv.conf"
do_install() {
install -m 0755 -d ${D}${systemd_unitdir}/system.conf.d
install -m 0755 ${WORKDIR}/defaultenv.conf ${D}${systemd_unitdir}/system.conf.d/90-defaultenv.conf
}
FILES_${PN} += "${systemd_unitdir}/system.conf.d"
这个在运行时和运行 systemctl set-environment CUSTOMENV=42
效果是一样的,可以用systemctl show-environment
.
来验证
但是,如果只需要为配方已经安装的systemd单元设置环境变量,修改单元文件(直接或使用sed -i
)来设置会更合适Environment
[exec]
部分中的选项。
是否可以从配方中设置 systemd 环境变量以在目标上执行与 'systemctl set-environment SOME_ENV_VAR' 相同的操作?
您的食谱可以安装 systemd.conf.d file to set the DefaultEnvironment
选项,例如
customrecipe/files/defaultenv.conf
[Manager] DefaultEnvironment=CUSTOMENV=42
customrecipe/customrecipe.bb
SUMMARY = "Example Recipe" LICENSE = "CLOSED" SRC_URI = "file://defaultenv.conf" do_install() { install -m 0755 -d ${D}${systemd_unitdir}/system.conf.d install -m 0755 ${WORKDIR}/defaultenv.conf ${D}${systemd_unitdir}/system.conf.d/90-defaultenv.conf } FILES_${PN} += "${systemd_unitdir}/system.conf.d"
这个在运行时和运行 systemctl set-environment CUSTOMENV=42
效果是一样的,可以用systemctl show-environment
.
但是,如果只需要为配方已经安装的systemd单元设置环境变量,修改单元文件(直接或使用sed -i
)来设置会更合适Environment
[exec]
部分中的选项。