Ask Your Question

Passing user data python script down and it only runs until reboot

asked 2013-11-11 17:00:42 -0500

B.Callanan gravatar image

When I send user-data through to the openstack Boot Api I send a custom Python script. The python script is successfully place on the VM in /var/lib/cloud/instance/scripts/part-001

The script successfully starts and runs just fine. The issue I have is the script is not run again after reboot.

In our API I send a file over and base64 encode the contents (See Below json_utility).

public static final String REQUEST_PARAM_USER_DATA="user_data"; // nova cli: --user-data

        String[][] paramValueArray = {
                {ApiPostServers.REQUEST_PARAM_IMAGE_REF, imageRef},
                {ApiPostServers.REQUEST_PARAM_FLAVOR_REF, flavorRef},
                {ApiPostServers.REQUEST_PARAM_NETWORKS, networkListBuilder.toString()},
                {ApiPostServers.REQUEST_PARAM_KEY_NAME, keyName},
                {ApiPostServers.REQUEST_PARAM_MAX_COUNT, "1"},
                {ApiPostServers.REQUEST_PARAM_MIN_COUNT, "1"},
                {ApiPostServers.REQUEST_PARAM_SECURITY_GROUPS, "default"},
    >>>>>       {ApiPostServers.REQUEST_PARAM_USER_DATA, "/opt/ensemble/json_utility"},
                {ApiPostServers.REQUEST_PARAM_META_DATA, ""},
                {ApiPostServers.REQUEST_PARAM_AVAILABILITY_ZONE, "nova"}

Is there a way to have it run on reboot that would, presumably, leave it out of /etc/init.d?

What openstack api setting might I use to accomplish this?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-11-11 18:33:03 -0500

larsks gravatar image

cloud-init is designed to run only once per instance (in order to avoid situations in which you manually configure an instance after it has first booted, only to have cloud-init clobber your changes on subsequent boots).

If you want your Python script to run at boot, you'll need to set it up the same way anything else runs at boot: as an init script (under RHEL) or as a systemd service (under Fedora). If you're feeling a little hacky, you can also do it via cron using the @reboot time specifier.

You would use cloud-init to put the script in the right place and run any additional commands to enable it at boot time.

edit flag offensive delete link more


going the cron job route. Thanks for the advice. Certainly will be digging through cloud-init to determine what it goes through when determining that the instance has booted up once. It must write out to a file or some location that it has already booted and run said script already.

B.Callanan gravatar imageB.Callanan ( 2013-11-12 06:39:34 -0500 )edit

That's correct. It creates semaphores in /var/lib/cloud/instances/INSTANCEID. While you could force it to run at every boot, the necessary changes to make that happen aren't any easier than just installing your script in the right place.

larsks gravatar imagelarsks ( 2013-11-13 07:48:31 -0500 )edit

answered 2013-11-12 08:23:37 -0500

B.Callanan gravatar image

Is it me or am I missing something.

On the VM, I can look through the log in:


I can see:

Nov 11 22:33:55 bono3 [CLOUDINIT] cloud-init-cfg[INFO]: cloud-init-cfg ['all', 'final']
Nov 11 22:33:55 bono3 [CLOUDINIT][DEBUG]: config-scripts-user already ran once-per-instance

So, I then run the following and it starts my script. This would suggest that cloud-init can be configured to always run. Is it that openstack has no way of telling the VM to configure it this way. And if so, do I have to edit the cloud-final.conf file to make it run this way?

/usr/bin/cloud-init-cfg scripts-user always
edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2013-11-11 17:00:42 -0500

Seen: 1,639 times

Last updated: Nov 12 '13