feniix
By:
feniix

How to make sure that cloud-init finished running?

July 31, 2015 5.1k views
System Tools Linux Basics CentOS Ubuntu

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.

1 comment
  • I am not sure of a quick way to do this but cloud-init will dump all output to /var/log/cloud-init-output.log on most distros and it does provide a standard statement printed to that file when the run completes. So you could check that file for the line that indicates that cloud-init completed.

2 Answers

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)
Have another answer? Share your knowledge.