By feniix
Hello,
is there any way to detect when cloud-init has finished running from bash?
I am using packer to create an image, and I do some init from there to get to a point where later I run puppet and other things that require my cloud-config settings to have finished running.
Is there a way to say something like:
while cloudconfigrunning; do
sleep 1
done
Ideally I would want to have a way that is platform agnostic.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
When cloud-init is finished running, it touches the file /var/lib/cloud/instance/boot-finished Checking for its existence is probably the simplest option. If you need to check that cloud-init finished without any error, you can also look at /var/lib/cloud/data/result.json A successful run would look like:
{
"v1": {
"errors": [],
"datasource": "DataSourceDigitalOcean"
}
}
While an unsuccessful one (this was just a bash script with exit 1) would look like:
{
"v1": {
"errors": [
"('scripts-user', RuntimeError('Runparts: 1 failures in 1 attempted commands',))"
],
"datasource": "DataSourceDigitalOcean"
}
}
For more complex uses, the phone_home module lets you POST to an arbitrary url with data about the system.
Looks like not, I have failed my deployment provisionar after 30 min, I checked manually to logged on to server to verify…
[root@nagios-log-server ~]# tail /var/lib/cloud/instance/boot-finished
tail: cannot open `/var/lib/cloud/instance/boot-finished' for reading: No such file or directory
[root@nagios-log-server ~]# ls -l /var/lib/cloud/instance/boot-finished
ls: cannot access /var/lib/cloud/instance/boot-finished: No such file or directory
[root@nagios-log-server ~]# ls -l /var/lib/cloud/instance/
ls: cannot access /var/lib/cloud/instance/: No such file or directory
[root@nagios-log-server ~]# ls -l /var/lib/cloud/
ls: cannot access /var/lib/cloud/: No such file or directory
[root@nagios-log-server ~]# ls -l /var/lib/
total 60
drwxr-xr-x 2 root root 4096 Dec 10 2015 alternatives
drwx------ 3 root root 4096 Mar 31 2015 authconfig
drwxr-xr-x 2 root root 4096 Jul 24 2015 dhclient
drwxr-xr-x 2 root root 4096 Sep 23 2011 games
drwxr-xr-x 8 root root 4096 Jul 23 2015 iscsi
-rw-r--r-- 1 root root 322 Jan 28 2015 logrotate.status
drwxr-xr-x 2 root root 4096 Dec 17 2013 misc
drwxr-xr-x 2 root root 4096 Aug 11 2014 plymouth
drwx------ 2 postfix root 4096 Nov 10 2015 postfix
-rw------- 1 root root 4096 Sep 15 09:43 random-seed
drwxr-xr-x 2 root root 4096 Sep 15 09:43 rpm
drwx------ 2 root root 4096 Dec 17 2014 rsyslog
drwxr-xr-x 4 root root 4096 Nov 10 2015 stateless
drwxr-xr-x 3 root root 4096 Jul 24 2015 udev
drwxr-xr-x 6 root root 4096 Dec 10 2015 yum
I manually created it, and re-ran my deployment
[root@nagios-log-server ~]# mkdir /var/lib/cloud/instance/
mkdir: cannot create directory `/var/lib/cloud/instance/': No such file or directory
[root@nagios-log-server ~]# mkdir /var/lib/cloud/instance/ -p
[root@nagios-log-server ~]# touch /var/lib/cloud/instance/boot-finished
[root@nagios-log-server ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
now you can use cloud init cli
$ cloud-init status
status: done
See https://cloudinit.readthedocs.io/en/latest/topics/cli.html#cli-status
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.