Advertisement
Guest User

Untitled

a guest
Jan 30th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. -bash-4.2$ cat plugins/ec2/AMI-Scripts/ubuntu-init.py
  2. #!/usr/bin/python
  3. import os
  4. import httplib
  5. import string
  6.  
  7. # To install run:
  8. # sudo wget http://$JENKINS_URL/plugin/ec2/AMI-Scripts/ubuntu-init.py -O /usr/bin/userdata
  9. # sudo chmod +x /etc/init.d/userdata
  10. # add the following line to /etc/rc.local "python /usr/bin/userdata"
  11.  
  12. # If java is installed it will be zero
  13. # If java is not installed it will be non-zero
  14. hasJava = os.system("java -version")
  15.  
  16. if hasJava != 0:
  17.     os.system("sudo apt-get update")
  18.     os.system("sudo apt-get install openjdk-7-jre -y")
  19.  
  20. conn = httplib.HTTPConnection("169.254.169.254")
  21. conn.request("GET", "/latest/user-data")
  22. response = conn.getresponse()
  23. userdata = response.read()
  24.  
  25. args = string.split(userdata, "&")
  26. jenkinsUrl = ""
  27. slaveName = ""
  28.  
  29. for arg in args:
  30.     if arg.split("=")[0] == "JENKINS_URL":
  31.         jenkinsUrl = arg.split("=")[1]
  32.     if arg.split("=")[0] == "SLAVE_NAME":
  33.         slaveName = arg.split("=")[1]
  34.  
  35. os.system("wget " + jenkinsUrl + "jnlpJars/slave.jar -O slave.jar")
  36. os.system("java -jar slave.jar -jnlpUrl " + jenkinsUrl + "computer/" + slaveName + "/slave-agent.jnlp")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement