How to re-run cloud-init without reboot

核能气质少年 提交于 2019-12-03 03:47:20

问题


I am using openstack to create a VM using 'nova boot' command. My image is cloud-init enabled. I pass a --user-data script which is a bash shell format for cloud-init to run during VM boot up time. All this happens successfully. Now my use-case is to re-run cloud-init to execute the same user-data script without rebooting the VM. I saw /usr/bin/cloud-init options and they do talk about running specific modules but nothing is able to make it execute the same user-data script. How can this be achieved ? Any help would be appreciated.


回答1:


In order for cloud-init to reset, you need to execute rm -rf /var/lib/cloud/instances.

Then re run the cloud-init start and it will run the full boot script process again.




回答2:


Since this keeps popping up in search results, what works for me:

  1. Delete semaphores in /var/lib/cloud/instances/i-xxxxxxx/sem. Cloud-init will not re-run if these files are present.
  2. Edit /var/lib/cloud/instances/i-xxxxxxxx/scripts/part-001. This is your user-data script.
  3. Execute only the user scripts module of cloud-init. This will not re-download user data but execute the already downloaded (and now, modified) script from step 2.

    sudo /usr/bin/cloud-init single -n cc_scripts_user




回答3:


The commands have been updated so to re-run you need to clean out the existing config:

sudo cloud-init clean

Then re-run it using the init directive:

sudo cloud-init init

Beware: things like ssh host keys maybe regenerated.




回答4:


To run the packages module of cloud-config part of cloud-init, you can run

# cloud-init-cfg all config

To run the runcmd module of cloud-config part of cloud-init, you can run

# cloud-init-cfg all final


来源:https://stackoverflow.com/questions/23065673/how-to-re-run-cloud-init-without-reboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!