summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog22
-rw-r--r--debian/control4
-rw-r--r--debian/ec2-config.cfg1
-rw-r--r--debian/init16
-rw-r--r--debian/install3
-rwxr-xr-xec2-fetch-credentials.py12
-rwxr-xr-xec2-run-user-data.py12
-rwxr-xr-xec2-set-apt-sources.py44
-rwxr-xr-xec2-set-defaults.py1
9 files changed, 82 insertions, 33 deletions
diff --git a/debian/changelog b/debian/changelog
index 94c79b83..736e0b82 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,15 +1,21 @@
+ec2-init (0.3.3ubuntu11) jaunty; urgency=low
+
+ * debian/control:
+ - Add python-cheetah and python-apt as a dependency.
+ * debian/ec2-config.cfg:
+ - Remove distro due to the change in ec2-set-apt-sources.py
+ * debian/inistall
+ - Install the templates in the right place.
+ * ec2-set-apt-sources.py:
+ - Use python-apt to update the sources.list.
+
+ -- Chuck Short <zulcss@ubuntu.com> Wed, 01 Apr 2009 13:58:43 -0400
+
ec2-init (0.3.3ubuntu10) jaunty; urgency=low
* ec2-set-hostname.py:
- Use template for /etc/hosts creation.
- - Dont use public_hostname in /etc/hosts. (LP: #352745)
- * debian/control:
- - Add python-cheetah as a depends.
- * templates/sources.list.tmpl:
- - Update template.
- * debian/init:
- - Run the ec2-user-data script last so that the users
- get a stable system before running the user scripts.
+ - Dont use public_hostname in /etc/hosts. (LP: #352745)
-- Chuck Short <zulcss@ubuntu.com> Wed, 01 Apr 2009 08:48:05 -0400
diff --git a/debian/control b/debian/control
index 05823938..e51482e0 100644
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,7 @@ Standards-Version: 3.8.0
Package: ec2-init
Architecture: i386 amd64
-Depends: python, procps, python-configobj, python-cheetah
-Description: Init scripts for EC2 instances
+Depends: python, procps, python-configobj, python-cheetah, python-apt
+Description: Init scripts for EC2 instances,
EC2 instances need special scripts to run during initialisation
to retrieve and install ssh keys and to let the user run various scripts.
diff --git a/debian/ec2-config.cfg b/debian/ec2-config.cfg
index ebf5eb69..76c81b77 100644
--- a/debian/ec2-config.cfg
+++ b/debian/ec2-config.cfg
@@ -1,3 +1,2 @@
user="ubuntu"
-distro="jaunty"
DISABLE_ROOT="1"
diff --git a/debian/init b/debian/init
index 113d8700..ea4f0acf 100644
--- a/debian/init
+++ b/debian/init
@@ -38,6 +38,14 @@ case "$1" in
log_end_msg 1
fi
+ log_daemon_msg "Running EC2 user data"
+ if ec2-run-user-data 2>&1 | logger -t "user-data"
+ then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+
log_daemon_msg "Setting hostname to EC2 public_hostname"
if ec2-set-hostname 2> /dev/null
then
@@ -53,14 +61,6 @@ case "$1" in
log_end_msg 1
fi
- log_daemon_msg "Running EC2 user data"
- if ec2-run-user-data 2>&1 | logger -t "user-data"
- then
- log_end_msg 0
- else
- log_end_msg 1
- fi
-
;;
stop)
exit 0
diff --git a/debian/install b/debian/install
index c2aa8811..33e2382f 100644
--- a/debian/install
+++ b/debian/install
@@ -1,2 +1,3 @@
debian/tmp/usr/sbin/*
-debian/tmp/etc/ec2-init/*
+debian/tmp/etc/ec2-init/templates/*
+debian/ec2-config.cfg etc/ec2-init
diff --git a/ec2-fetch-credentials.py b/ec2-fetch-credentials.py
index 52176003..68922878 100755
--- a/ec2-fetch-credentials.py
+++ b/ec2-fetch-credentials.py
@@ -20,6 +20,8 @@
#
import urllib
import os
+import socket
+import sys
from configobj import ConfigObj
api_ver = '2008-02-01'
@@ -60,6 +62,16 @@ def setup_root_user(k,root_config):
else:
print "%s - I dont understand that opion."
+def checkServer():
+ s = socket.socket()
+ try:
+ address = '169.254.169.254'
+ port = 80
+ s.connect((address,port))
+ except socket.error, e:
+ print "!!! Unable to connect to %s" % address
+ sys.exit(0)
+
os.umask(077)
if user == "":
print "User must exist in %s" %(filename)
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
index 56e5e538..ef3b86b1 100755
--- a/ec2-run-user-data.py
+++ b/ec2-run-user-data.py
@@ -23,11 +23,22 @@ import os
import sys
import tempfile
import urllib
+import socket
from time import gmtime, strftime
api_ver = '2008-02-01'
metadata = None
+def checkServer():
+ s = socket.socket()
+ try:
+ address = '169.254.169.254'
+ port = 80
+ s.connect((address,port))
+ except socket.error, 0:
+ print "!!!! Unable to connect to %s" % address
+ sys.exit(0)
+
def get_user_data():
url = 'http://169.254.169.254/%s/user-data' % api_ver
fp = urllib.urlopen(url)
@@ -40,6 +51,7 @@ def get_ami_id():
ami_id = urllib.urlopen('%s/ami-id/' %url).read()
return ami_id
+checkServer()
user_data = get_user_data()
amiId = get_ami_id()
filename = '/var/ec2/.already-ran.%s' % amiId
diff --git a/ec2-set-apt-sources.py b/ec2-set-apt-sources.py
index 0cf4f09d..46ca0a48 100755
--- a/ec2-set-apt-sources.py
+++ b/ec2-set-apt-sources.py
@@ -21,8 +21,21 @@
import os
import sys
import urllib
+import socket
+import apt
+import apt_pkg
from Cheetah.Template import Template
+def checkServer():
+ s = socket.socket()
+ try:
+ address = '169.254.169.254'
+ port = 80
+ s.connect((address,port))
+ except socket.error, e:
+ print "!!! Unable to connect to %s." % address
+ sys.exit(0)
+
def detectZone():
api_ver = '2008-02-01'
metadat = None
@@ -36,18 +49,25 @@ def detectZone():
return(archive)
-t = os.popen("lsb_release -c").read()
-codename = t.split()
-mirror = detectZone()
-distro = codename[1]
+def updateList():
+ mirror = detectZone()
+ if not os.path.exists("/var/run/ec2/sources.lists"):
+ t = os.popen("lsb_release -c").read()
+ codename = t.split()
+ distro = codename[1]
-mp = {'mirror' : mirror, 'codename' : distro}
-t = Template(file="/etc/ec2-init/templates/sources.list.tmpl", searchList=[mp])
+ mp = {'mirror' : mirror, 'codename' : distro}
+ t = Template(file="/etc/ec2-init/templates/sources.list.tmpl", searchList=[mp])
+ f = open("/var/run/ec2/sources.list", "w")
+ f.write('%s' %(t))
+ f.close()
-f = open("/var/run/ec2/sources.list", "w")
-f.write('%s' %(t))
-f.close()
+ if not os.path.exists("/etc/apt/sources.list-ec2-init"):
+ os.system("mv /etc/apt/sources.list /etc/apt/sources.list-ec2-init")
+ os.symlink("/var/run/ec2/sources.list", "/etc/apt/sources.list")
+ cache = apt.Cache(apt.progress.OpProgress())
+ prog = apt.progress.FetchProgress()
+ cache.update(prog)
-os.system("mv /etc/apt/sources.list /etc/apt/sources.list-ec2-init")
-os.system("ln -s /var/run/ec2/sources.list /etc/apt/sources.list")
-os.system("apt-get update 2>&1 > /dev/null")
+checkServer()
+updateList()
diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py
index d7de9f1f..7d410031 100755
--- a/ec2-set-defaults.py
+++ b/ec2-set-defaults.py
@@ -24,7 +24,6 @@ import os
api_ver = '2008-02-01'
metadata = None
-filename='/etc/ec2-init/ec2-config.cfg'
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
zone = urllib.urlopen('%s/placement/availability-zone' % base_url).read()