【发布时间】: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