systemd:“环境";设置PATH的指令 [英] systemd: "Environment" directive to set PATH

查看:1657
本文介绍了systemd:“环境";设置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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆