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

时间:2022-09-23 17:35:07

I took the userdata for the ElasticBeanstalk AMI to try and add some stuff of my own. Should be easy.

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

Specially because there is already a session in the userdata where some shell script is run. So I put my stuff there and it gets completely ignored. It doesn't run, it doesn't log anything, it produces exactly zero results.

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

Anyone knows why?

谁知道为什么?

This is the original user-data:

这是原始用户数据:

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

I'm trying to add this series of commands to it:

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

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

So I placed them at the end of the Content-Type: text/x-shellscript; section of this multipart. Tried at the beggining too, to no avail.

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

Any ideas?

有任何想法吗?

1 个解决方案

#1


0  

User Data on Linux servers must have #! on the first line, otherwise it is not executed as a script.

Linux服务器上的用户数据必须有#!在第一行,否则它不作为脚本执行。

If you wish to add software to an Elastic Beanstalk environment, you should use .ebextensions.

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

See: Advanced Environment Customization with Configuration Files (.ebextensions) - AWS Elastic Beanstalk

请参阅:使用配置文件进行高级环境自定义(.ebextensions) - AWS Elastic Beanstalk

#1


0  

User Data on Linux servers must have #! on the first line, otherwise it is not executed as a script.

Linux服务器上的用户数据必须有#!在第一行,否则它不作为脚本执行。

If you wish to add software to an Elastic Beanstalk environment, you should use .ebextensions.

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

See: Advanced Environment Customization with Configuration Files (.ebextensions) - AWS Elastic Beanstalk

请参阅:使用配置文件进行高级环境自定义(.ebextensions) - AWS Elastic Beanstalk