【问题标题】:Running job on Bamboo "Not privileged to remove service." on osx在 Bamboo 上运行作业“无权删除服务”。在 osx 上
【发布时间】:2021-01-20 20:12:31
【问题描述】:
当我运行脚本时:
launchctl remove com.apple.CoreSimulator.CoreSimulatorService
在构建机器上的终端中它工作正常,但是当我从竹子运行它时它失败并且在日志中我看到“没有特权删除服务。”。我尝试回显用户 ID,它在终端和竹日志中是相同的。我不明白为什么会这样。请问,您知道如何解决吗?它也不适用于 sudo。
【问题讨论】:
标签:
macos
service
bamboo
access-rights
【解决方案1】:
根据Bruce Tu的回答:
您的 Bamboo-Agent 作为 launchDaemon 而不是 launchAgent 运行。
要解决此问题,您必须将 com.atlassian.bamboo-agent.plist 文件从 /Library/LaunchDaemons 移动到 /Library/LaunchAgents 并重新启动服务器。
然后您可以将其添加到您的竹子构建脚本中以解决 CoreSimulator 问题:
killall -9 com.apple.CoreSimulator.CoreSimulatorService || true
launchctl remove com.apple.CoreSimulator.CoreSimulatorService || true
【解决方案2】:
我在 Jenkins 构建中遇到了同样的问题。我的解决方案也可能适用于 Bamboo。
我通过在构建开始之前运行的 shell 脚本中运行以下命令来解决它。
这假设您无需输入密码即可允许 sudo。
如果没有,您也可以使用 chown -R the user:group 来执行杀戮/删除。
希望这会有所帮助。
sudo chmod -R g-w $(xcode-select -p)/Library/PrivateFrameworks/CoreSimulator.framework/Versions/A/XPCServices/com.apple.CoreSimulator.CoreSimulatorService.xpc
sudo chown -R root:wheel $(xcode-select -p)/Library/PrivateFrameworks/CoreSimulator.framework/Versions/A/XPCServices/com.apple.CoreSimulator.CoreSimulatorService.xpc
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService || true
sudo launchctl remove com.apple.CoreSimulator.CoreSimulatorService || true
【解决方案4】:
尝试使用 sudo -u"USER" launchctl remove <service> 在根上下文中启动 LaunchAgent 时遇到相同的错误。
这里的问题是sudo -u 并非在所有情况下都有效(例如:当它用于包的安装后脚本时)。
解决方案:
使用sudo -u 和launchctl asuser <userId> 的组合
launchctl asuser <uid> sudo -u <uName> launchctl load -S Aqua -w "/Library/LaunchAgents/<plist>"
该组合保证有效。