summaryrefslogtreecommitdiff
path: root/ec2-run-user-data.py
diff options
context:
space:
mode:
authorChuck Short <zulcss@ubuntu.com>2009-02-04 17:54:00 +0000
committerBazaar Package Importer <jamesw@ubuntu.com>2009-02-04 17:54:00 +0000
commit40bc760f17a67700ad19b0d2250deec4e5e06954 (patch)
tree6f803f5fe1adcb08268e4037e349513aa7d83f83 /ec2-run-user-data.py
parentdb066b9caf770d7cdcf9f46f159249d22db99142 (diff)
downloadvyos-cloud-init-40bc760f17a67700ad19b0d2250deec4e5e06954.tar.gz
vyos-cloud-init-40bc760f17a67700ad19b0d2250deec4e5e06954.zip
* 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.
Diffstat (limited to 'ec2-run-user-data.py')
-rwxr-xr-xec2-run-user-data.py26
1 files changed, 16 insertions, 10 deletions
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)