简体   繁体   English

EC2 cloud-init 脚本未在用户数据更新时更新

[英]EC2 cloud-init script not updated on userdata update

I have the following user-data to pull and run a docker image:我有以下用户数据来拉取和运行 docker 图像:

#cloud-config
cloud_final_modules:
 - [scripts-user, always]
runcmd:
  - "docker pull private-image:commit-b8212047"
  - "docker run private-image:commit-b8212047"

It works perfectly.它工作得很好。

But when I update userdata and put an updated script with another Docker image tag, the new script version is not executed.但是当我更新用户数据并将更新的脚本与另一个 Docker 图像标签放在一起时,新脚本版本不会执行。 The old initial version of the script is always executed on instance reboots or start/stops and the initial Docker image version is always pulled and run.脚本的旧初始版本始终在实例重启或启动/停止时执行,初始 Docker 映像版本始终被拉取并运行。 How to fix that?如何解决?

Update: My investigations led me to the /var/lib/cloud/instance/scripts/runcmd file which contains my script.更新:我的调查使我找到了包含我的脚本的/var/lib/cloud/instance/scripts/runcmd文件。 But its content is not updated even when /var/lib/cloud/instance/cloud-config.txt and /var/lib/cloud/instance/user-data.txt have the updated data.但是即使/var/lib/cloud/instance/cloud-config.txt/var/lib/cloud/instance/user-data.txt有更新的数据,它的内容也不会更新。 Why it doesn't update the script?为什么它不更新脚本?

The issue is that the runcmd script is copied to disk by the following directive (set by default):问题是 runcmd 脚本通过以下指令(默认设置)复制到磁盘:

cloud_config_modules:
 - runcmd

But by default, cloud-init uses the instance repetition value.但默认情况下,cloud-init 使用instance重复值。 That means the runcmd module will be executed only once on an instance.这意味着runcmd模块将只在一个实例上执行一次。 To fix that, and to execute my script on every boot, the following configuration is required:要解决这个问题,并在每次启动时执行我的脚本,需要以下配置:

cloud_config_modules: 
 - [runcmd, always] # copies the runcmd script from userdata to disk

cloud_final_modules: 
 - [scripts-user, always] # executes the runcmd script

Beware that I've omitted other modules here that may be required for the proper instance configuration.请注意,我在这里省略了正确实例配置可能需要的其他模块。 I just highlighted settings that resolved my issue.我只是突出显示了解决我的问题的设置。

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

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