简体   繁体   中英

EC2 cloud-init script not updated on userdata update

I have the following user-data to pull and run a docker image:

#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. 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. How to fix that?

Update: My investigations led me to the /var/lib/cloud/instance/scripts/runcmd file which contains my script. 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. 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):

cloud_config_modules:
 - runcmd

But by default, cloud-init uses the instance repetition value. That means the runcmd module will be executed only once on an instance. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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