systemd:“环境";设置PATH的指令 [英] systemd: "Environment" directive to set PATH
问题描述
在systemd
单位文件中设置PATH变量的正确方法是什么?
看了几个例子之后,我尝试使用下面的格式,但是变量似乎没有扩展.
What is the right way to set PATH variable in a systemd
unit file?
After seeing a few examples, I tried to use the format below, but the variable doesn't seem to expand.
Environment="PATH=/local/bin:$PATH"
我正在使用以下版本的systemd在CoreOS上尝试此操作.
I am trying this on CoreOS with the below version of systemd.
systemd 225
-PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT -GNUTLS -ACL +XZ -LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD -IDN
推荐答案
您不能在Environment
指令中使用EnvVars
.整个Environment=
将被忽略.如果使用EnvironmentFile=
,则将加载指定文件而不替换.因此PATH=/local/bin:$PATH
恰好是 ,而这可能不是您想要的.
You can't use EnvVars
in Environment
directives. The whole Environment=
will be ignored. If you use EnvironmentFile=
, then the specified file will be loaded without substitution. So PATH=/local/bin:$PATH
would be exactly that, and this is probably not what you want.
在CentOS7下,以下工作.
Under CentOS7 the following works.
# /etc/systemd/system/nagios.service.d/env.conf
[Service]
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
> sudo systemctl daemon-reload
> sudo systemctl restart nagios
> sudo cat /proc/28647/environ
...
PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
...
这篇关于systemd:“环境";设置PATH的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!