Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run cloud-init manually?

I'm writing a CloudFormation template and I'm trying to debug the user-data script I provide in the template. How can I run the cloud-init manually and make it perform the same actions it does when starting a new instance?

like image 997
Fluffy Avatar asked Apr 18 '14 09:04

Fluffy


People also ask

How do I rerun cloud-init manually?

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.

How do I know if cloud-init is running?

You can check the /var/lib/cloud/data/status. json for cloud-init status. Or if the host is using upstart, add one init process in /etc/init/newprocess. conf and newprocess.


Video Answer


2 Answers

You can just run it like this:

/usr/bin/cloud-init -d init 

This runs the cloud init setup with the initial modules. (The -d option is for debug) If want to run all the modules you have to run:

/usr/bin/cloud-init -d modules 

Keep in mind that the second time you run these it doesn't do much since it has already run at boot time. To force to run after boot time you can run from the command line:

( cd /var/lib/cloud/ && sudo rm -rf * ) 

In older versions the equivalent of cloud-init init is:

/usr/bin/cloud-init start 

You may also find this question useful although it applies to the older versions of cloud-init: How do I make cloud-init startup scripts run every time my EC2 instance boots?

The documentation for cloud init here just gives you examples. But it doesn't explain the command line options or each one of the modules, so you have to play around with different values in the config to get your desired results. Of course you can also look at the code.

like image 54
Rico Avatar answered Sep 21 '22 18:09

Rico


rm -f /var/log/cloud-init.log \ && rm -Rf /var/lib/cloud/* \ && cloud-init -d init \ && cloud-init -d modules --mode final 
like image 20
Sergey Safarov Avatar answered Sep 21 '22 18:09

Sergey Safarov