diff options
-rwxr-xr-x | ec2-init | 85 | ||||
-rwxr-xr-x | ec2-set-defaults.py | 12 | ||||
-rw-r--r-- | ec2init/__init__.py | 13 | ||||
-rwxr-xr-x | setup.py | 5 | ||||
-rw-r--r-- | templates/sources.list.tmpl | 4 |
5 files changed, 91 insertions, 28 deletions
@@ -16,10 +16,6 @@ NAME=ec2-init . /lib/lsb/init-functions -if [ ! -d /var/run/ec2 ]; then - mkdir /var/run/ec2 -fi - run_once() { per_id=$1 action_id=$2 @@ -62,8 +58,63 @@ regenerate_ssh_host_keys() { echo "#############################################################" } +# fix LP bug 458850 +# the ephemeral mounts provided in eucalyptus instances differ from +# those found in ec2 in 2 ways: +# 1. independent of arch type, the filesystem is on /dev/sda2 +# 2. the filesystem is ext2, not ext3 +fix_euca_fstab() { + + local edev="/dev/sda2" eedev='\/dev\/sda2' + + [ -e "${edev}" ] || return 0 + + local sops=""; # sed operations + local mntinfo="" file_out="" sops="" umdev=${edev} + + # if /dev/sdb is set to mount to /mnt, then we + # want to rewrite that to be /dev/sda2 + mntinfo=$(awk '$2 == "/mnt" { printf("dev=%s fs=%s\n",$1,$3); }' /etc/fstab) + case "${mntinfo}" in + dev=/dev/sdb\ *) + umdev=/dev/sdb; + sops="${sops:+${sops};}s,^/dev/sdb,${edev},";; + esac + + # if fstab says ext3, but fs on edev is ext2, switch fstab + case "${mntinfo}" in + *\ fs=ext3) + file_out=$(file --special-files "${edev}") + case "${file_out}" in + *ext2*) sops="${sops:+${sops};}/^${eedev}/s/ext3/ext2/;";; + esac + ;; + esac + + # if there were no sed operations to preform, then nothing to do + [ -n "${sops}" ] || return 0 + + log_daemon_msg "Fixing fstab for eucalyptus" + sed -i "${sops}" /etc/fstab + # subsequent boots, /etc/fstab will be updated, and the mount + # here isn't needed, but if modifications were made, it is + umount "${edev}" >/dev/null 2>&1 + [ "${edev}" = "${umdev}" ] || umount "${umdev}" >/dev/null 2>&1 + mount "${edev}" + log_end_msg $? +} + case "$1" in start) + if ! ec2-is-compat-env --quiet; then + log_daemon_msg "ec2-init disabled" + log_end_msg 0 + exit 0 + fi + if [ ! -d /var/run/ec2 ]; then + mkdir /var/run/ec2 + fi + log_daemon_msg "Waiting for EC2 meta-data service" if ec2-wait-for-meta-data-service then @@ -73,9 +124,22 @@ case "$1" in exit 1 fi + # fix euca_fstab for ephemeral mounts one time ever + # on rebundle, it should collect the fixed /etc/fstab + if run_once_ever euca-fix-fstab-for-ephemeral; then + fix_euca_fstab + fi + if run_once_per_ami ssh_host_key_regeneration then - regenerate_ssh_host_keys 2>&1 | logger -s -t "ec2" + # we can't be certain that rsyslog is up (or configured to send + # messages to console), but we want to make sure this goes to + # console. So write to /dev/console directly through tee. + # Change priority of message, so if user.notice (logger's default) + # also goes to /dev/console , we could avoid dup messages + regenerate_ssh_host_keys 2>&1 | + logger -p user.info -s -t "ec2" 2>&1 | + tee /dev/console fi if run_once_ever ec2-defaults @@ -104,20 +168,11 @@ case "$1" in if ec2-set-hostname 2> /dev/null then log_end_msg 0 + invoke-rc.d rsyslog reload else log_end_msg 1 fi - if run_once_per_ami user-data - then - 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 - fi ;; stop) exit 0 diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py index 4191538e..364225aa 100755 --- a/ec2-set-defaults.py +++ b/ec2-set-defaults.py @@ -28,10 +28,16 @@ def main(): ec2 = ec2init.EC2Init() availability_zone = ec2.get_availability_zone() - location = ec2.get_location_from_availability_zone(availability_zone) - mirror = ec2.get_mirror_from_availability_zone(availability_zone) - locale = ec2.location_locale_map[location] + try: + location = ec2.get_location_from_availability_zone(availability_zone) + locale = ec2.location_locale_map[location] + except Exception, e: + locale = "en_US.UTF-8" + + # get_mirror_from_availability_zone returns default on no match + mirror = ec2.get_mirror_from_availability_zone(availability_zone) + apply_locale(locale) generate_sources_list(mirror) diff --git a/ec2init/__init__.py b/ec2init/__init__.py index 0f161d7d..3bd1d23e 100644 --- a/ec2init/__init__.py +++ b/ec2init/__init__.py @@ -88,12 +88,13 @@ class EC2Init(): return hostname def get_mirror_from_availability_zone(self, availability_zone): - if availability_zone.startswith("us"): - return 'http://us.ec2.archive.ubuntu.com/ubuntu/' - elif availability_zone.startswith("eu"): - return 'http://eu.ec2.archive.ubuntu.com/ubuntu/' - - return 'http://archive.ubuntu.com/ubuntu/' + # availability is like 'us-west-1b' or 'eu-west-1a' + try: + host="%s.ec2.archive.ubuntu.com" % availability_zone[:-1] + socket.getaddrinfo(host, None, 0, socket.SOCK_STREAM) + return 'http://%s/ubuntu/' % host + except: + return 'http://archive.ubuntu.com/ubuntu/' def wait_for_metadata_service(self): timeout = 2 @@ -34,10 +34,11 @@ setup(name='EC2-init', 'ec2-run-user-data.py', 'ec2-set-defaults.py', 'ec2-set-hostname.py', - 'ec2-wait-for-meta-data-service.py'], + 'ec2-wait-for-meta-data-service.py', + 'ec2-is-compat-env'], data_files=[('/etc/ec2-init', ['ec2-config.cfg']), ('/etc/ec2-init/templates', glob('templates/*')), - ('/etc/init.d', ['ec2-init']), + ('/etc/init.d', ['ec2-init', 'ec2-init-user-data']), ('/usr/share/ec2-init', ['ec2-init-appliance-ebs-volume-mount.sh']), ], ) diff --git a/templates/sources.list.tmpl b/templates/sources.list.tmpl index 59dfa959..36615099 100644 --- a/templates/sources.list.tmpl +++ b/templates/sources.list.tmpl @@ -2,5 +2,5 @@ deb $mirror $codename main universe deb-src $mirror $codename main universe deb $mirror $codename-updates main universe deb-src $mirror $codename-updates main universe -deb http://security.ubuntu.com/ubuntu $codename-security main restricted -deb-src http://security.ubuntu.com/ubuntu $codename-security main restricted +deb http://security.ubuntu.com/ubuntu $codename-security main universe +deb-src http://security.ubuntu.com/ubuntu $codename-security main universe |