Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30183

Openstack Cloud Plugin does not wait until the user data script completes

      I created a script in "Openstack User Data" section in Jenkins Management that is supposed to load some files to the new node before any jenkins job can be launched.
      it's a shell script that calls a python script at the end.

      I see that sometimes the jenkins job is started on the new node BEFORE the init script completes, which is not acceptable.

      are there any examples available on how to make sure "Openstack User Data" script completes before any jobs are started on that node?

          [JENKINS-30183] Openstack Cloud Plugin does not wait until the user data script completes

          Alex Java created issue -
          Alex Java made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]

          There is a way to do this using JNLP launch initiated as the last thing from your cloud-init. There is no way known to me to wait for cloud-init completion when connecting over SSH.

          Oliver Gondža added a comment - There is a way to do this using JNLP launch initiated as the last thing from your cloud-init. There is no way known to me to wait for cloud-init completion when connecting over SSH.

          What we do is have our Jenkins user created as the very last step of the user data scripts.

          That keeps Jenkins from connecting into the node until it's actually ready.

          Andrew Grimberg added a comment - What we do is have our Jenkins user created as the very last step of the user data scripts. That keeps Jenkins from connecting into the node until it's actually ready.
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 165273 ] New: JNJira + In-Review [ 181905 ]

          Joshua Harlow added a comment -

          So over at godaddy we are moving towards this plugin and our existing solution has been to spin-up a tiny webserver (either via apache) or via python via something like the following (this would happen as the last thing cloud-init via user data script does):

          $ python -m SimpleHTTPServer 8888
          

          Then have the code that provisioned that server (ie, the openstack cloud plugin here), poll for a given period of time trying to access the above port, if the port doesn't become accessible after some configurable amount of time, then assume the server is busted (and the VM is dead); otherwise assume everything worked out.

          Another option (and I'm not really sure how/if it could work) is to take advvantage of the cloud-init feature to callback to a URL as the last thing that it does when running (ie after all the other user data scripts have ran): example @ https://github.com/number5/cloud-init/blob/master/doc/examples/cloud-config-phone-home.txt#L3

          If that could be used to somehow post back to the jenkins master that the 'slave is now ready for usage' that'd be even better (less polling required). Anyone know which approach people would be ok with? Both would require a version of cloud-init installed (which is in most/all images), the later would be nice, but unsure if jenkins has such an ability in the first place (how does it know slaves are ready to be used?).

          Joshua Harlow added a comment - So over at godaddy we are moving towards this plugin and our existing solution has been to spin-up a tiny webserver (either via apache) or via python via something like the following (this would happen as the last thing cloud-init via user data script does): $ python -m SimpleHTTPServer 8888 Then have the code that provisioned that server (ie, the openstack cloud plugin here), poll for a given period of time trying to access the above port, if the port doesn't become accessible after some configurable amount of time, then assume the server is busted (and the VM is dead); otherwise assume everything worked out. Another option (and I'm not really sure how/if it could work) is to take advvantage of the cloud-init feature to callback to a URL as the last thing that it does when running (ie after all the other user data scripts have ran): example @ https://github.com/number5/cloud-init/blob/master/doc/examples/cloud-config-phone-home.txt#L3 If that could be used to somehow post back to the jenkins master that the 'slave is now ready for usage' that'd be even better (less polling required). Anyone know which approach people would be ok with? Both would require a version of cloud-init installed (which is in most/all images), the later would be nice, but unsure if jenkins has such an ability in the first place (how does it know slaves are ready to be used?).

          Oliver Gondža added a comment - - edited

          I have considered the phone home feature though there are several caveats:

          • Cloud-init can be user written and therefore the directive might be missing. Adding it at the end of the script by the plugin sounds problematic.
          • Cloud init does not necessarily have to use #cloud-config format, it can be bash, powershell or other script. I do not think plugin should manipulate any of them.
          • Not all images have that feature enabled. If user-data are sent and not supported by image - nothing really happens. If Jenkins would wait for a signal to arrive it would be a problem for such images.

          Oliver Gondža added a comment - - edited I have considered the phone home feature though there are several caveats: Cloud-init can be user written and therefore the directive might be missing. Adding it at the end of the script by the plugin sounds problematic. Cloud init does not necessarily have to use #cloud-config format, it can be bash, powershell or other script. I do not think plugin should manipulate any of them. Not all images have that feature enabled. If user-data are sent and not supported by image - nothing really happens. If Jenkins would wait for a signal to arrive it would be a problem for such images.

          Why do you need a web server running on your slaves ahead of time? Please elaborate further.

          Oliver Gondža added a comment - Why do you need a web server running on your slaves ahead of time? Please elaborate further.
          Oliver Gondža made changes -
          Assignee Original: Marat Mavlyutov [ mavlyutov ] New: Oliver Gondža [ olivergondza ]

          My current thinking is using marker entries in openstack server console log. Iff there is OPENSTACK_USER_DATA_START logged, the plugin would wait for OPENSTACK_USER_DATA_DONE. Existing scripts would work as before since the first marker would never appear. So does images/setups without cloud-init/cloud-config. If someone is doing complicated setup, they will log extra 2 lines to the output from the script they prefer.

          Oliver Gondža added a comment - My current thinking is using marker entries in openstack server console log. Iff there is OPENSTACK_USER_DATA_START logged, the plugin would wait for OPENSTACK_USER_DATA_DONE . Existing scripts would work as before since the first marker would never appear. So does images/setups without cloud-init/cloud-config. If someone is doing complicated setup, they will log extra 2 lines to the output from the script they prefer.

            olivergondza Oliver Gondža
            alskor Alex Java
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: