EC2用户数据脚本被完全忽略

时间:2018-05-11 20:41:42

标签: amazon-web-services amazon-ec2

我使用了ElasticBeanstalk AMI的userdata来尝试添加我自己的一些东西。应该很容易。

特别是因为在userdata中已经有一个会话,其中运行了一些shell脚本。所以我把我的东西放在那里,它完全被忽略了。它不会运行,它不会记录任何内容,它会产生完全零结果。

任何人都知道为什么?

这是原始用户数据:

Content-Type: multipart/mixed; boundary="===============5189065377222898407=="
MIME-Version: 1.0

--===============5189065377222898407==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
repo_upgrade: none
repo_releasever: 2017.09
cloud_final_modules:
 - [scripts-user, always]

--===============5189065377222898407==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="user-data.txt"

#!/bin/bash
exec > >(tee -a /var/log/eb-cfn-init.log|logger -t [eb-cfn-init] -s 2>/dev/console) 2>&1
echo [`date -u +"%Y-%m-%dT%H:%M:%SZ"`] Started EB User Data
set -x


function sleep_delay 
{
  if (( $SLEEP_TIME < $SLEEP_TIME_MAX )); then 
    echo Sleeping $SLEEP_TIME
    sleep $SLEEP_TIME  
    SLEEP_TIME=$(($SLEEP_TIME * 2)) 
  else 
    echo Sleeping $SLEEP_TIME_MAX  
    sleep $SLEEP_TIME_MAX  
  fi
}

# Executing bootstrap script
SLEEP_TIME=10
SLEEP_TIME_MAX=3600
while true; do 
  curl https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/UserDataScript.sh > /tmp/ebbootstrap.sh 
  RESULT=$?
  if [[ "$RESULT" -ne 0 ]]; then 
    sleep_delay 
  else
    /bin/bash /tmp/ebbootstrap.sh     'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/aws-elasticbeanstalk-tools-1.20-1.noarch.rpm'    'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/awseb-ruby-2.2.4-x86_64-20160503_1008.tar.gz https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/basehooks.tar.gz'    'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/beanstalk-core-2.11.gem https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/beanstalk-core-healthd-1.1.gem https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_node_js_4.0.1.143.7/lib/executor-1.2.gem'    'https://cloudformation-waitcondition-us-west-2.s3-us-west-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-west-2%3A731735707548%3Astack/awseb-e-qprmcmyjbp-stack/261dc900-e722-11e7-bcbb-503ac9ec2461/AWSEBInstanceLaunchWaitHandle?AWSAccessKeyId=AKIAIY5RM4DUXMU25KNA&Expires=1514038355&Signature=Nha6e4UQYJLWCOjxnj7nHXYzFDY%3D'    'arn:aws:cloudformation:us-west-2:731735707548:stack/awseb-e-qprmcmyjbp-stack/261dc900-e722-11e7-bcbb-503ac9ec2461'    'us-west-2'    '30755f954950'    'e9af7960-20f2-46da-9353-a69cb7dedeff'    ''    'nginx'    ''    && 
    exit 0  
  fi 
done

--===============5189065377222898407==-- ##Ec2InstanceReplacementRequest=7577e7d0-ebe5-11e7-bd10-6bec9097cbda

我正在尝试添加这一系列命令:

aws s3 cp s3://oidevops/beanstalk/application-configs/chatbot-admin/dev/91_install_cloudwatchlogs_agent.sh .
aws s3 cp s3://oidevops/beanstalk/application-configs/chatbot-admin/dev/91_awslogs_restart.sh .
chmod 750 91install_cloudwatchlogs_agent.sh && chmod 750 91_awslogs_restart.sh
cp 91_install_cloudwatchlogs_agent.sh /opt/elasticbeanstalk/hooks/appdeploy/post
cp 91_awslogs_restart.sh /opt/elasticbeanstalk/hooks/restartappserver/post
cp 91_awslogs_restart.sh /opt/elasticbeanstalk/hooks/configdeploy/post

所以我把它们放在这个多部分的Content-Type: text/x-shellscript;部分的末尾。试图在开始时也无济于事。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Linux服务器上的用户数据必须在第一行有#!,否则不会以脚本形式执行。

如果您希望将软件添加到Elastic Beanstalk环境,则应使用.ebextensions

请参阅:Advanced Environment Customization with Configuration Files (.ebextensions) - AWS Elastic Beanstalk