【问题标题】:CHEF: HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directoryCHEF:必须设置 HOME 环境变量(或 HOMEDRIVE 和 HOMEPATH)并指向一个目录
【发布时间】:2016-08-02 07:00:24
【问题描述】:

我正在尝试通过执行 memcached chef recipe 来自动化 aws ec2 memcached 实例引导。我正在从云形成 UserData 部分调用 shell 脚本名称 cache-init.sh。我的 shell 脚本中有以下步骤:

我正在运行 AMI RHEL 6.7 版本

!/bin/bash

init () {
BINARIES=/root/.binaries
PROFILE_SCRIPT=/etc/profile.d/instance_profile.sh
APPLICATION_RELEASE_VERSION="app-v3.0.1"
CHEF_ZIP="app-chef-${APPLICATION_RELEASE_VERSION}.zip"
APP_FILES="${CHEF_ZIP}"
HOME=/root
}

# Initializing the script vairables.
 init

# Create chef folders
 mkdir /root/.chef;
 mkdir /root/.metadata;

# Disable rhui-lb plugin, this has an issue in RHEL within VPC
 sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/rhui-lb.conf

# Print all environment varialbes in log
 set > /root/.metadata/metadata.txt


# Update ${PROFILE_SCRIPT}
 echo "export HOME=${HOME}" >> ${PROFILE_SCRIPT};
 chmod 644 ${PROFILE_SCRIPT};
 log 'Added ${PROFILE_SCRIPT}';

 echo ${HOME}

# Install chef
# Set these just for Chef installation
/usr/bin/curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v    11.16.2-1;
chef_version=`chef-solo --version`;
log "Installed Chef Version : $chef_version in /opt/chef " ;

log "Installing ChefDk"
/usr/bin/curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -c current -P chefdk

chef-repo=/root/.chef/chef-repo
memcached_cookbook=${chef-repo}/cookbooks/memcached
cd ${memcached_cookbook}


# download and package the dependencies.
chef exec berks install
chef exec berks vendor

log "memcached dependencies downloaded and packaged"

cp -r berks-cookbooks/runit /root/.chef/itduzzit/cookbooks
cp -r berks-cookbooks/yum /root/.chef/itduzzit/cookbooks
cp -r berks-cookbooks/yum-epel /root/.chef/itduzzit/cookbooks
cp -r berks-cookbooks/packagecloud /root/.chef/itduzzit/cookbooks

# Clean up the dependencies.
rm -rf berks-cookbooks

berks install 命令执行后,出现以下错误:

/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rb-readline-0.5.3/lib/rbreadline.rb:1097:in <module:RbReadline>: HOME environment variable   (or HOMEDRIVE and HOMEPATH) must be set and point to a directory (RuntimeError)
 from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rb-readline-    0.5.3/lib/rbreadline.rb:17:in <top (required)>
 from ...
 from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/berkshelf-4.3.2/bin/berks:3:in `<top (required)>'
 from /usr/bin/berks:49:in `load'
 from /usr/bin/berks:49:in `<main>'

我尝试通过在 cache-init.sh 脚本的开头导出它来设置 HOME env 变量,但仍然遇到相同的错误。当我 ssh 到盒子并手动运行脚本时,它工作正常。我尝试搜索错误,但没有找到合适的修复程序。非常感谢这里的任何帮助。

【问题讨论】:

  • 请说明您是如何设置环境变量的。
  • @coderanger 我已经用我的脚本更新了这个问题。

标签: amazon-web-services chef-infra amazon-cloudformation berkshelf


【解决方案1】:

在 init 下,应该是 export HOME=...(其他所有内容都一样。如果没有 export,您将创建一个 bash 变量,但不是环境变量。

【讨论】:

  • 我正在使用以下命令将变量保存在 /etc/profile.d/instance_profile.sh 中:echo "export HOME=${HOME}" &gt;&gt; ${PROFILE_SCRIPT};
  • 这对同一个脚本后面的命令没有影响,一般来说对服务或其他非交互式会话完全没有影响。
  • 我的问题得到了解决,感谢您的帮助,最初是在我写export HOME=/root in the /etc/profile.d/instance_profile.sh 时,后来我意识到它只是在 shell 启动时提供的。由于我的脚本是由云形成脚本直接调用的,因此它从未得到源代码,从而导致错误。我更改了我的脚本,并在脚本正文中明确执行了export HOME=/root,使其可用作 berkshelf 的 berks 命令的环境变量并解决了该问题。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-11
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2013-06-30
  • 2021-02-01
  • 1970-01-01
相关资源
最近更新 更多