简体   繁体   English

Ubuntu ec2实例无法运行userdata脚本

[英]Ubuntu ec2 instance fails to run userdata script

I am trying to execute a script which needs to be run on Ubuntu 14.04 ec2 instance whenever the instance or it's image in auto scaling group spins up- 我试图执行一个脚本,只要实例或它在自动缩放组中的图像旋转,需要在Ubuntu 14.04 ec2实例上运行 -

#!/bin/bash-x
REGION=`curl http://169.254.169.254/latest/dynamic/instance-    identity/document|grep region|awk -F\" '{print $4}'`
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
cd
wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xzvf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure
make
sudo make install
apt-get install apache2 
cd /home/ubuntu  
wget https://aws-codedeploy-$REGION.s3.amazonaws.com/latest/install
chmod +x ./install
./install auto

But the script never runs. 但脚本永远不会运行。 I went to cloud-init-output.log file and following is the log details- 我去了cloud-init-output.log文件,以下是日志详细信息 -

Cloud-init v. 0.7.5 running 'modules:final' at Mon, 12 Dec 2016 15:54:20 +0000. Up 36.92 seconds.
2016-12-12 15:54:20,432 - util.py[WARNING]: Failed running     /var/lib/cloud/instance/scripts/part-001 [-]
2016-12-12 15:54:20,436 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2016-12-12 15:54:20,436 - util.py[WARNING]: Running scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scrip$
Cloud-init v. 0.7.5 finished at Mon, 12 Dec 2016 15:54:20 +0000.     Datasource DataSourceEc2.  Up 37.11 seconds

Specifically, I am trying to achieve is to install codedeploy in the instance. 具体来说,我试图实现的是在实例中安装codedeploy。

To test this, I launched an Amazon Linux EC2 instance with #!/bin/bash-x at the top of the User Data. 为了测试这一点,我在用户数据的顶部用#!/bin/bash-x启动了一个Amazon Linux EC2实例。

The log said: 日志说:

/bin/sh: /var/lib/cloud/instance/scripts/part-001: /bin/bash-x: bad interpreter: No such file or directory

I re-launched it without the -x and it worked fine. 我重新启动它没有-x ,它工作正常。

So, that is definitely the cause of the problem for Amazon Linux. 所以,这肯定是亚马逊Linux问题的原因。 Things might be different with Ubuntu. Ubuntu可能会有所不同。

Update: As per sqlbot's suggestion (below), I tried it again with #!/bin/bash -x (a space before -x ) and it worked fine. 更新:根据sqlbot的建议(下面),我用#!/bin/bash -x-x之前的空格)再次尝试了它,它运行正常。

The shebang you have used is wrong. 你用过的shebang是错的。

Change #!/bin/bash-x to #!/bin/bash #!/bin/bash-x更改为#!/bin/bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM