summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog20
-rw-r--r--debian/dirs2
-rw-r--r--debian/init14
-rwxr-xr-xec2-fetch-credentials.py12
-rwxr-xr-xec2-run-user-data.py26
-rwxr-xr-xec2-set-hostname.py12
6 files changed, 62 insertions, 24 deletions
diff --git a/debian/changelog b/debian/changelog
index 6b2006a9..1f720438 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,23 @@
+ec2-init (0.3.2) jaunty; urgency=low
+
+ * debian/init:
+ - Remove already ran detection
+ - Log the running of ec2-run-user-data to /var/log/ec2-user-data.log
+ * ec2-set-hostname.py:
+ - set hostname to the Ec2 local-hostname
+ - Update the /etc/hosts to change the ubuntu hostname to the
+ public hostname.
+ * ec2-fetch-credentials:
+ - Copy the ssh keys to the ubuntu user.
+ - Setup authorized keys for root to tell the user to login as the
+ ubuntu user when they try to connect.
+ * ec2-run-user-data:
+ - Create an .already-ran file to check to see if ec2-run-user-data
+ already ran.
+ - Save the ec2-run-user-data script in /var/ec2.
+
+ -- Chuck Short <zulcss@ubuntu.com> Wed, 04 Feb 2009 09:32:08 -0500
+
ec2-init (0.3.1) jaunty; urgency=low
* debian/dir: Install /var/ec2 to save user-data scripts.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644
index 00000000..19be79b3
--- /dev/null
+++ b/debian/dirs
@@ -0,0 +1,2 @@
+var/ec2
+usr/sbin
diff --git a/debian/init b/debian/init
index 24db3845..e28edd06 100644
--- a/debian/init
+++ b/debian/init
@@ -1,7 +1,7 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: ec2-init
-# Required-Start: $network $local_fs
+# Required-Start: $network $local_fs $ssh
# Required-Stop:
# Should-Start: $named
# Should-Stop:
@@ -27,17 +27,11 @@ case "$1" in
fi
log_daemon_msg "Running EC2 user data"
- if [ -f /var/ec2/.already_ran ]
+ if ec2-run-user-data 2>&1 | tee /var/log/ec2-user-data.log
then
- echo "Already ran";
+ log_end_msg 0
else
- if ec2-run-user-data 2> /dev/null
- then
- log_end_msg 0
- touch /var/ec2/.already_ran
- else
- log_end_msg 1
- fi
+ log_end_msg 1
fi
if pgrep nash-hotplug > /dev/null
diff --git a/ec2-fetch-credentials.py b/ec2-fetch-credentials.py
index 80980924..1e91bef8 100755
--- a/ec2-fetch-credentials.py
+++ b/ec2-fetch-credentials.py
@@ -34,10 +34,16 @@ keys = get_ssh_keys()
os.umask(077)
-if not os.path.exists('/root/.ssh'):
- os.mkdir('/root/.ssh')
+if not os.path.exists('/home/ubuntu/.ssh'):
+ os.mkdir('/home/ubuntu/.ssh')
-fp = open('/root/.ssh/authorized_keys', 'a')
+fp = open('/home/ubuntu/.ssh/authorized_keys', 'a')
fp.write(''.join(['%s\n' % key for key in keys]))
fp.close()
+os.system('chown -R ubuntu:ubuntu /home/ubuntu/.ssh')
+
+fp = open('/root/.ssh/authorized_keys', 'a')
+fp.write("command=\"echo;echo \'Please use the \"ubuntu\" user to login on this host instead of \"root\".\'echo;sleep 10\"")
+fp.write('',join(['%s\n' % key for key in keys]))
+fp.close()
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
index 428c270e..63820bed 100755
--- a/ec2-run-user-data.py
+++ b/ec2-run-user-data.py
@@ -36,21 +36,27 @@ def get_user_data():
return data
def get_ami_id():
- url = 'http://169.254.169.254/%s/meta-data', % api_ver
+ url = 'http://169.254.169.254/%s/meta-data' % api_ver
ami_id = urllib.urlopen('%s/ami-id/' %url).read()
return ami_id
user_data = get_user_data()
amiId = get_ami_id()
+filename = '/var/ec2/.already-ran.%s' % amiId
-if user_data.startswith('#!'):
- # run it
- (fp, path) = tempfile.mkstemp()
- os.write(fp,user_data)
- os.close(fp);
- os.chmod(path, 0700)
- os.system('cp %s /var/ec2/user-data.%s' %(path, amiId))
- status = os.system('%s' % path)
- os.unlink(path)
+if os.path.exists(filename):
+ print "ec2-run-user-data already ran for this instance."
+ sys.exit(0)
+else:
+ if user_data.startswith('#!'):
+ # run it
+ (fp, path) = tempfile.mkstemp()
+ os.write(fp,user_data)
+ os.close(fp);
+ os.chmod(path, 0700)
+ os.system('cp %s /var/ec2/user-data' %(path))
+ status = os.system('%s' % path)
+ os.unlink(path)
+ os.system('touch /var/ec2/$s' %(filename))
sys.exit(0)
diff --git a/ec2-set-hostname.py b/ec2-set-hostname.py
index 4c8d7416..f12a4a30 100755
--- a/ec2-set-hostname.py
+++ b/ec2-set-hostname.py
@@ -25,5 +25,15 @@ api_ver = '2008-02-01'
metadata = None
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
-my_hostname = urllib.urlopen('%s/public-hostname/' % base_url).read()
+my_hostname = urllib.urlopen('%s/local-hostname/' % base_url).read()
os.system('hostname %s' % my_hostname)
+
+# replace the ubuntu hostname in /etc/hosts
+my_public_hostname = urllib.urlopen('%s/public-hostname/' % base_url).read()
+
+f = open("/etc/hosts", "r")
+lines = f.read()
+f.close()
+file = open("/etc/hosts", "w")
+file.write(lines.replace("127.0.1.1 ubuntu. ubuntu", "127.0.1.1 "+ my_public_hostname +" "+ my_hostname))
+file.close()