我正在写一本 Chef 食谱来安装Hubot。在配方中,我执行以下操作:
bash "install hubot" do
user hubot_user
group hubot_group
cwd install_dir
code <<-EOH
wget https://github.com/downloads/github/hubot/hubot-#{node['hubot']['version']}.tar.gz && \
tar xzvf hubot-#{node['hubot']['version']}.tar.gz && \
cd hubot && \
npm install
EOH
end
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在安装食谱的服务器上运行 Chef-client 时,我获得了写入到运行 Chef-client 的用户目录而不是 hubot 用户的权限被拒绝的权限。出于某种原因,npm
试图在错误的用户下运行,而不是在 bash 资源中指定的用户下。
我可以sudo su - hubot -c "npm install /usr/local/hubot/hubot"
手动运行,这得到了我想要的结果(将 hubot 安装为 hubot 用户)。但是,似乎chef-client 并没有以hubot 用户的身份执行命令。您将在下面找到厨师 - 客户执行。先感谢您。
Saving to: `hubot-2.1.0.tar.gz'
0K ...... 100% 563K=0.01s
2012-01-23 12:32:55 (563 KB/s) - `hubot-2.1.0.tar.gz' saved [7115/7115]
npm ERR! Could not create /home/<user-chef-client-uses>/.npm/log/1.2.0/package.tgz
npm ERR! Failed creating the tarball.
npm ERR! couldn't pack /tmp/npm-1327339976597/1327339976597-0.13104878342710435/contents/package to /home/<user-chef-client-uses>/.npm/log/1.2.0/package.tgz
npm ERR! error installing hubot@2.1.0 Error: EACCES, permission denied '/home/<user-chef-client-uses>/.npm/log'
...
npm not ok
---- End output of "bash" "/tmp/chef-script20120123-25024-u9nps2-0" ----
Ran "bash" "/tmp/chef-script20120123-25024-u9nps2-0" returned 1
Run Code Online (Sandbox Code Playgroud)
问题(可能)不是 Chef 以错误的用户身份运行命令,而是运行脚本的 shell 不是登录 shell。这意味着某些环境变量(如 HOME)不会按照您期望的方式设置,从而导致 npm 尝试将文件写入错误的位置。
该问题在问题 CHEF-2288 中讨论。虽然这仍然很突出,但您可以尝试HOME=/home/hubot-user
在调用 npm 之前添加代码块。
小智 5
摘自CHEF-2288 中的评论:
environment ({ 'HOME' => ::Dir.home('USERNAME'), 'USER' => 'USERNAME' })
为我工作!
在你的情况下:
environment ({ 'HOME' => ::Dir.home(hubot_user), 'USER' => hubot_user })
归档时间: |
|
查看次数: |
8460 次 |
最近记录: |