composer.phar安装问题(cloudinit与手动)



我面临一个奇怪的问题。当厨师从用户数据(cloudinit)执行时,我下面的厨师食谱失败了。

它要求HOME/COMPOSER_HOME环境变量。

然而,如果我从SSH终端手动运行chef客户端(甚至直接在终端上运行命令),它运行得很好。

PS:composer.phar和composer.json由开发者提供(捆绑在wordpresszip中)

===配方代码段===

# Install Composer
script "install_composer" do
    interpreter "bash"
    user "root"
    cwd "#{node.apache.default_docroot}/html"
    code <<-EOH
    /opt/rh/rh-php56/root/usr/bin/php composer.phar install
    EOH
    not_if {File.exists?("#{node.default_docroot}/html/composer.lock")}
end

===从SSH终端运行时===

  * script[install_composer] action run
    - execute "bash"  "/tmp/chef-script20160722-5397-1sjwxg9"

===Cloud-Init-Output.log片段===

================================================================================
Error executing action `run` on resource 'script[install_composer]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20160722-2013-r6sdpo" ----
STDOUT: 
STDERR: [RuntimeException]                                                                        
  The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
---- End output of "bash"  "/tmp/chef-script20160722-2013-r6sdpo" ----
Ran "bash"  "/tmp/chef-script20160722-2013-r6sdpo" returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/webps-commportal/recipes/wordpress.rb
 49: script "install_composer" do
 50:    interpreter "bash"
 51:    user "root"
 52:    cwd "#{node.apache.default_docroot}/html"
 53:    code <<-EOH
 54:    /opt/rh/rh-php56/root/usr/bin/php composer.phar install
 55:    EOH
 56:    not_if {File.exists?("#{node.apache.default_docroot}/html/composer.lock")}
 57: end
 58: 
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/webps-commportal/recipes/wordpress.rb:49:in `from_file'
script("install_composer") do
  action "run"
  retries 0
  retry_delay 2
  guard_interpreter :default
  command ""bash"  "/tmp/chef-script20160722-2013-r6sdpo""
  backup 5
  cwd "/opt/rh/httpd24/root/var/www/html"
  returns 0
  user "root"
  code "t/opt/rh/rh-php56/root/usr/bin/php composer.phar installn"
  interpreter "bash"
  cookbook_name "webps-commportal"
  recipe_name "wordpress"
  not_if { #code block }
end
---- Begin output of "bash"  "/tmp/chef-script20160722-2013-r6sdpo" ----
STDOUT: 
STDERR: [RuntimeException]                                                                        
  The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
---- End output of "bash"  "/tmp/chef-script20160722-2013-r6sdpo" ----
Ran "bash"  "/tmp/chef-script20160722-2013-r6sdpo" returned 1

environment HOME: '/root'添加到script资源(或类似资源)中。这是必需的,因为Chef不会为您设置此变量。当您通过SSH登录时,它会由登录shell设置,然后继承到chef客户端进程。

相关内容

  • 没有找到相关文章

最新更新