$ salt --versions-report
Salt: 0.17.2
Python: 2.7.6 (default, Nov 19 2013, 02:02:54)
Jinja2: 2.7.1
M2Crypto: 0.21.1
msgpack-python: 0.4.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
PyYAML: 3.10
PyZMQ: 14.0.0
ZMQ: 3.2.4
$ sudo salt'*'pkg.list_pkgs
MacBook-Pro.local:
----------
from:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in,/usr/local/Library/Homebrew/global.rb:25:in,/usr/local/Library/Homebrew/global.rb:44,/usr/local/Library/brew.rb:17,/usr/local/Library/brew.rb:17:in
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in:
`expand_path':
$ sudo salt'*'pkg.list_upgrades
MacBook-Pro.local:
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path': couldn't find HOME environment -- expanding `~/Library/Caches/Homebrew' (ArgumentError)
- from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path'
- from /usr/local/Library/Homebrew/global.rb:25:in `cache'
- from /usr/local/Library/Homebrew/global.rb:44
- from /usr/local/Library/brew.rb:17:in `require'
- from /usr/local/Library/brew.rb:17
但是从命令行运行brew
工作正常:
$ brew list --versions
cairo 1.12.16
ccze 0.2.1
cmake 2.8.12.1
curl 7.33.0
fontconfig 2.11.0
$ brew outdated
freetype (2.5.0.1 < 2.5.1)
imagemagick (6.8.7-0 < 6.8.7-7)
libpng (1.5.14 < 1.5.17)
passenger (4.0.24 < 4.0.26)
pixman (0.32.2 < 0.32.4)
zeromq (3.2.4 < 4.0.3)
我怀疑它是由不同版本的Ruby引起的:
$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]
$(which ruby) -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
$ brew doctor
Your system is ready to brew.
尝试从命令行扩展仍然有效:
$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -ve 'p ENV["HOME"]'
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]
"/Users/quanta"
$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -ve 'p File.expand_path("~")'
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]
"/Users/quanta"
答案 0 :(得分:0)
通过在ENV['HOME']
文件中手动定义/usr/local/Library/brew.rb
来解决问题:
ENV['HOME'] = "/Users/quanta"
$ sudo salt&#39; *&#39; pkg.list_upgrades
MacBook-Pro.local:
- freetype
- imagemagick
- libpng
- mysql
- passenger
- pixman
- redis
- zeromq
但我的问题仍然存在:为什么盐可以成为HOME
环境变量?
更新Sun Dec 8 15:26:03 ICT 2013
由于salt-minion
是通过launchctl启动的:
com.saltstack.minion.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.saltstack.minion</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/salt-minion</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
我想到了一个问题:如何在launchd脚本中指定环境变量?答案是:
EnvironmentVariables <dictionary of strings>
This optional key is used to specify additional environmental variables to be set before running the job.
所以我将以下内容添加到plist文件中:
<dict>
<key>HOME</key>
<string>/Users/quanta</string>
</dict>
然后重新启动了minion服务,现在它正常工作。