composer.phar安装问题(cloudinit vs manual)

时间:2016-07-22 08:46:24

标签: wordpress amazon-web-services composer-php chef cloud-init

我面临一个奇怪的问题。当从用户数据(cloud-init)执行厨师时,我的以下主厨配方失败。

它要求HOME / COMPOSER_HOME env变量。

然而,如果我从SSH终端运行手动厨师客户端(甚至直接在终端上运行命令),它运行正常。

PS:composer.phar和composer.json由Developers提供(捆绑在wordpress zip中)

== Recipe Snippet ==

# 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 install\n"
  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

1 个答案:

答案 0 :(得分:1)

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