systemd 将/bin 添加到环境路径 [英] systemd prepending /bin to Environment PATH

查看:37
本文介绍了systemd 将/bin 添加到环境路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Bamboo 代理设置为系统服务.服务文件如下所示:

I'm trying to setup my Bamboo agents as a systemd service. The service file looks like this:

[Unit]
Description=Atlassian Bamboo Agent
After=syslog.target network.target

[Service]
Type=forking
User=bamboo
Group=bamboo
ExecStart=/opt/bamboo-1/bin/bamboo-agent.sh start
ExecStop=/opt/bamboo-1/bin/bamboo-agent.sh stop
Environment="PATH=/opt/rh/devtoolset-3/root/bin/:/usr/local/bin:/usr/bin"

[Install]
WantedBy=multi-user.target

当我检查进程环境时,PATH 已正确设置为我期望的值,唯一的例外是我的 PATH 以 /bin 开头.

When I check the process environment, the PATH is correctly set to what I expect, with with the only exception that my PATH is prepended with /bin.

cat /proc/12345/environ <--- 12345 is my Bamboo PID
...
PATH=/bin:/opt/rh/devtoolset-3/root/bin/:/usr/local/bin:/usr/bin
...

这意味着我的构建将使用错误的 gcccmake

That means my builds will use the wrong gcc, cmake, etc.

有什么办法可以防止将 /bin 放在 PATH 前面?

Is there any way to prevent /bin to be prepended to the PATH?

推荐答案

我创建了一个测试服务,它在使用新路径设置 Environment= 后打印出路径,并发现它按预期工作在 Ubuntu 16.04 上使用 systemd 229.

I created a test service that just printed out the path after setting Environment= with a new path, and found it worked as expected on Ubuntu 16.04 with systemd 229.

我得出结论,您脚本中的某些内容将/bin 预先添加到您的环境中.

I conclude that something in your script is pre-pending /bin to your environment.

systemd.exec 手册页中没有任何内容表明 systemd 旨在按照您观察的方式运行.

Nothing in the systemd.exec man page suggests that systemd is designed to behave the way you observe.

这篇关于systemd 将/bin 添加到环境路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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