我正在尝试通过执行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到框并手动运行脚本时,它工作正常。我尝试搜索错误,但没有找到合适的修复程序。非常感谢这里的任何帮助。
答案 0 :(得分:0)
在init下,它应该是export HOME=...
(对于其他所有内容都是相同的。如果没有export
,则创建一个bash变量而不是环境变量。