--- ec2-init-0.4.99.orig/ec2-init +++ ec2-init-0.4.99/ec2-init @@ -104,6 +104,7 @@ if ec2-set-hostname 2> /dev/null then log_end_msg 0 + invoke-rc.d rsyslog reload else log_end_msg 1 fi --- ec2-init-0.4.99.orig/ec2-config.cfg +++ ec2-init-0.4.99/ec2-config.cfg @@ -1,2 +1,2 @@ -user="ubuntu" -DISABLE_ROOT="1" +user=ubuntu +disable_root=1 --- ec2-init-0.4.99.orig/ec2-fetch-credentials.py +++ ec2-init-0.4.99/ec2-fetch-credentials.py @@ -19,6 +19,7 @@ # import os import pwd +import sys import ec2init @@ -27,8 +28,10 @@ pwent = pwd.getpwnam(user) - if not os.path.exists('%s/.ssh' % pwent.pw_dir): - os.mkdir('%s/.ssh' % pwent.pw_dir) + ssh_dir = '%s/.ssh' % pwent.pw_dir + if not os.path.exists(ssh_dir): + os.mkdir(ssh_dir) + os.chown(ssh_dir, pwent.pw_uid, pwent.pw_gid) authorized_keys = '%s/.ssh/authorized_keys' % pwent.pw_dir fp = open(authorized_keys, 'a') @@ -43,9 +46,12 @@ ec2 = ec2init.EC2Init() user = ec2.get_cfg_option_str('user') - disable_root = ec2.get_cfg_option_bool('disable_root') + disable_root = ec2.get_cfg_option_bool('disable_root', True) - keys = ec2.get_ssh_keys() + try: + keys = ec2.get_ssh_keys() + except Exception, e: + sys.exit(1) if user: setup_user_keys(keys, user, '') @@ -55,7 +61,7 @@ else: key_prefix = '' - setup_root_user(keys, 'root', key_prefix) + setup_user_keys(keys, 'root', key_prefix) if __name__ == '__main__': main() --- ec2-init-0.4.99.orig/ec2-get-info.py +++ ec2-init-0.4.99/ec2-get-info.py @@ -45,7 +45,7 @@ api_ver = '2008-02-01' metadata = None base_url = 'http://169.254.169.254/%s/meta-data' % api_ver - data = urllib.urlopen('%s/%s/' %(base_url,ec2data)).read() + data = urllib.urlopen('%s/%s' %(base_url,ec2data)).read() print "%s: %s" %(ec2data,data) def showAllData(ec2Data): @@ -53,7 +53,7 @@ metadata = None base_url = 'http://169.254.169.254/%s/meta-data' % api_ver for x in ec2Data: - data = urllib.urlopen('%s/%s/' %(base_url,x)).read() + data = urllib.urlopen('%s/%s' %(base_url,x)).read() print "%s: %s" %(ec2data,data) def main(): --- ec2-init-0.4.99.orig/ec2-set-defaults.py +++ ec2-init-0.4.99/ec2-set-defaults.py @@ -36,19 +36,23 @@ generate_sources_list(mirror) +def render_to_file(template, outfile, searchList): + t = Template(file='/etc/ec2-init/templates/%s.tmpl' % template, searchList=[searchList]) + f = open(outfile, 'w') + f.write(t.respond()) + f.close() + def apply_locale(locale): subprocess.Popen(['locale-gen', locale]).communicate() subprocess.Popen(['update-locale', locale]).communicate() + render_to_file('default-locale', '/etc/default/locale', { 'locale' : locale }) + def generate_sources_list(mirror): stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() codename = stdout.strip() - mp = { 'mirror' : mirror, 'codename' : codename } - t = Template(file='/etc/ec2-init/templates/sources.list.tmpl', searchList=[mp]) - f = open('/etc/apt/sources.list', 'w') - f.write(t.respond()) - f.close() + render_to_file('sources.list', '/etc/apt/sources.list', { 'mirror' : mirror, 'codename' : codename }) if __name__ == '__main__': main() --- ec2-init-0.4.99.orig/ec2init/__init__.py +++ ec2-init-0.4.99/ec2init/__init__.py @@ -53,20 +53,20 @@ os.system(bailout_command) return False - def get_cfg_option_bool(self, key): - val = self.config[key] + def get_cfg_option_bool(self, key, default=None): + val = self.config.get(key, default) if val.lower() in ['1', 'on', 'yes']: return True return False - def get_cfg_option_str(self, key): - return config[key] + def get_cfg_option_str(self, key, default=None): + return self.config.get(key, default) def get_ssh_keys(self): conn = urllib2.urlopen('%s/public-keys/' % self.meta_data_base_url) data = conn.read() keyids = [line.split('=')[0] for line in data.split('\n')] - return [urllib.urlopen('%s/public-keys/%d/openssh-key' % (self.meta_data_base_url, int(keyid))).read().rstrip() for keyid in keyids] + return [urllib2.urlopen('%s/public-keys/%d/openssh-key' % (self.meta_data_base_url, int(keyid))).read().rstrip() for keyid in keyids] def get_user_data(self): return boto.utils.get_instance_userdata() --- ec2-init-0.4.99.orig/templates/default-locale.tmpl +++ ec2-init-0.4.99/templates/default-locale.tmpl @@ -0,0 +1 @@ +LANG="$locale" --- ec2-init-0.4.99.orig/debian/compat +++ ec2-init-0.4.99/debian/compat @@ -0,0 +1 @@ +5 --- ec2-init-0.4.99.orig/debian/ec2-init.rightscale-init.init +++ ec2-init-0.4.99/debian/ec2-init.rightscale-init.init @@ -0,0 +1,103 @@ +#!/bin/bash +# +# This script will configure an Ubuntu server for use with RightScale +# + +start() { + ## First check to see if we were launched through RightScale. Exit and remove if not... + user_data=`curl -s -S -f -L --retry 7 -w ' %{http_code}' http://169.254.169.254/latest/user-data` + if `echo $user_data | grep -v "RS_token=" 1>/dev/null 2>&1` ; then + ## Remove this init script so that it does not run again + remove + exit 0 + fi + + ## ok, we were launched through RightScale, so let's continue + echo "Detected a RightScale instance..." + echo "Beginning configuration..." + + ## figure out which version of RightScale to install... + export rs_release=Ubuntu_`lsb_release -rs` + + ## Install some necessary packages + echo "Installing necessary packages..." + export DEBIAN_FRONTEND=NONINTERACTIVE + apt-get update + apt-get install -y binutils ruby1.8 sysv-rc-conf unzip ruby1.8-dev build-essential autoconf automake libtool logrotate rsync openssl ca-certificates libopenssl-ruby1.8 + + ## Add rightscale customizations + echo "Installing RightScale" + curl -s -S -f -L --retry 7 -w ' %{http_code}' -o /tmp/rightscale_scripts.tgz http://s3.amazonaws.com/rightscale_scripts/rightscale_scripts_"$rs_release".tgz + tar -xzf /tmp/rightscale_scripts.tgz -C /opt/ + ln -f /opt/rightscale/etc/init.d/rightscale /etc/init.d/rightscale + chmod +x /opt/rightscale/etc/init.d/rightscale + chmod +x /etc/init.d/rightscale + mkdir -p /etc/rightscale.d + update-rc.d rightscale start 98 2 3 4 5 . stop 1 0 1 6 . + ln -sf /usr/bin/ruby1.8 /usr/bin/ruby + ln -f /opt/rightscale/etc/motd /etc/motd + echo $rs_release > /etc/rightscale-release + + ## Add rubygems 1.8 + echo "Installing RubyGems 1.8..." + curl -s -S -f -L --retry 7 -w ' %{http_code}' -o /tmp/rubygems.tgz http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz + mkdir -p /tmp/rubygems + tar -xzvf /tmp/rubygems.tgz -C $root/tmp/rubygems + cd /tmp/rubygems/rubygems-1.3.1/ + ruby setup.rb --no-rdoc --no-ri + ln -s /usr/bin/gem1.8 /usr/bin/gem + gem source -a http://ec2-us-east-mirror.rightscale.com/rubygems/archive/latest/ + gem source -r http://mirror.rightscale.com + gem install --no-rdoc --no-ri xml-simple net-ssh net-sftp s3sync + updatedb + + ## Add some links to keep things inline + ln -s /usr/lib/site_ruby/aes /usr/local/lib/site_ruby/1.8/aes + ln -s /usr/lib/site_ruby/ec2 /usr/local/lib/site_ruby/1.8/ec2 + ln -s /usr/bin/env /bin/env + + ## Insert 'ec2' as the cloud + echo "ec2" > /etc/rightscale.d/cloud + + ## Enable root logins + echo "Enabling root logins..." + cp -f /home/ubuntu/.ssh/authorized_keys /root/.ssh/. + + ## Remove the default sources.list becasue RightScale will create a better one anyways... + rm -f /etc/apt/sources.list.d/amazon.list + + ## Remove this init script so that it does not run again + remove + + ## Start the rightscale service + echo "Starting RightScale..." + /etc/init.d/rightscale start + echo "RightScale services started properly" + +} + +stop() { + exit 0 +} + +remove() { + my_name=`readlink -e $0` + update-rc.d -f `basename $my_name` remove + rm -f $my_name +} + + +# See how we were called. +case "$1" in + start) + start >>/var/log/install 2>&1 + ;; + stop) + stop >>/var/log/install 2>&1 + ;; + *) + echo $"Usage: $0 {start|stop}" + exit 1 +esac + +exit $? --- ec2-init-0.4.99.orig/debian/pycompat +++ ec2-init-0.4.99/debian/pycompat @@ -0,0 +1 @@ +2 --- ec2-init-0.4.99.orig/debian/copyright +++ ec2-init-0.4.99/debian/copyright @@ -0,0 +1,27 @@ +This package was debianized by Soren Hansen on +Thu, 04 Sep 2008 12:49:15 +0200. + +Upstream Author: + + Soren Hansen + Chuck Short + +Copyright: + + Copyright 2008-2009 Canonical Ltd. + +License: + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +The complete text of the GPL version 3 can be seen in /usr/share/common-licenses/GPL. --- ec2-init-0.4.99.orig/debian/install +++ ec2-init-0.4.99/debian/install @@ -0,0 +1,3 @@ +#debian/ec2-init/usr/bin/* +#debian/ec2-init/etc/ec2-init/templates/* +#debian/ec2-config.cfg etc/ec2-init --- ec2-init-0.4.99.orig/debian/rules +++ ec2-init-0.4.99/debian/rules @@ -0,0 +1,12 @@ +#!/usr/bin/make -f + +DEB_PYTHON_SYSTEM=pycentral +include /usr/share/cdbs/1/class/python-distutils.mk +include /usr/share/cdbs/1/rules/debhelper.mk +DEB_DH_INSTALLINIT_ARGS=-o + +DEB_UPDATE_RCD_PARAMS:= start 15 2 3 4 5 . stop 20 1 . + +binary-install/ec2-init:: + for x in $(DEB_DESTDIR)/usr/bin/*.py; do mv "$$x" "$${x%.py}"; done + dh_installinit -p ec2-init --name rightscale-init -- defaults 99 09 --- ec2-init-0.4.99.orig/debian/dirs +++ ec2-init-0.4.99/debian/dirs @@ -0,0 +1 @@ +/var/lib/ec2 --- ec2-init-0.4.99.orig/debian/control +++ ec2-init-0.4.99/debian/control @@ -0,0 +1,15 @@ +Source: ec2-init +Section: admin +Priority: extra +Maintainer: Soren Hansen +Build-Depends: cdbs, debhelper (>= 5.0.38), python-all-dev (>= 2.3.5-11), python-central (>= 0.5.6) +XS-Python-Version: all +Standards-Version: 3.8.0 + +Package: ec2-init +Architecture: all +Depends: python, procps, python-configobj, python-cheetah, update-motd, python-boto, ${python:Depends} +XB-Python-Version: ${python:Versions} +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. --- ec2-init-0.4.99.orig/debian/changelog +++ ec2-init-0.4.99/debian/changelog @@ -0,0 +1,288 @@ +ec2-init (0.4.99-0ubuntu3) karmic; urgency=low + + * Also update /etc/default/locale when setting the locale based on + locality. + + -- Soren Hansen Tue, 11 Aug 2009 21:49:33 +0200 + +ec2-init (0.4.99-0ubuntu2) karmic; urgency=low + + * Consolidate build-dependencies a bit. + * Sync default configuration with code. + * Create /var/lib/ec2 in package. + * Make ec2-get-info more robust in testing environments. + * Handle missing public keys more gracefully. + * Set proper ownership of user's authorized_keys. + + -- Soren Hansen Tue, 11 Aug 2009 09:54:16 +0200 + +ec2-init (0.4.99-0ubuntu1) karmic; urgency=low + + * Massive rewrite. (LP: #407871, #407919, #308530, #407949, #407950, #407892 + and probably many others) + * First Ubuntu version with the upstream tarball split out. + * Switch to arch: all. There is no arch specific code here. + + -- Soren Hansen Tue, 11 Aug 2009 08:33:33 +0200 + +ec2-init (0.3.4ubuntu9) karmic; urgency=low + + * Really include the action id in the semaphore filename. + + -- Soren Hansen Sat, 11 Jul 2009 09:50:31 +0200 + +ec2-init (0.3.4ubuntu8) karmic; urgency=low + + * Add Vcs-Bzr header to debian/control. + * Include the action id in the semaphore filename. + + -- Soren Hansen Sat, 11 Jul 2009 02:35:43 +0200 + +ec2-init (0.3.4ubuntu7) karmic; urgency=low + + * Re-add accidentally removed locale template. + * Fix indentation in init script. + + -- Soren Hansen Fri, 10 Jul 2009 23:47:27 +0200 + +ec2-init (0.3.4ubuntu6) karmic; urgency=low + + * Replace calls to ec2-get-data with calls to ec2-get-info. + * Make this package arch: all. + + -- Soren Hansen Fri, 10 Jul 2009 23:16:35 +0200 + +ec2-init (0.3.4ubuntu5) karmic; urgency=low + + * debian/init: Move instance reboot detection out of python + scripts and move them to the init script. + * debian/ec2-set-defaults.py: + - Point to the right location for locate (LP: #387611) + - Default to UTC (LP: #341060) + * debian/ec2-set-apt-sources.py: If you cant contact EC2 then use the + regular archive (LP: #387027) + * debian/ec2-setup-hostname.py: Use the local hostname in /etc/hosts + and dont change once rebooted. (LP: #352745) + + -- Chuck Short Wed, 08 Jul 2009 09:48:49 -0400 + +ec2-init (0.3.4ubuntu4) karmic; urgency=low + + * debian/init: Run update-motd regardless whether its a firstboot or not. + * debian/init: Fix comments (LP: #373057) + * debian/control: Add update-motd as a depends. + * ec2-set-defaults.py: Wait for network to become available. (LP: #308530) + + -- Chuck Short Thu, 28 May 2009 05:04:31 -0400 + +ec2-init (0.3.4ubuntu3) karmic; urgency=low + + * debian/init: Move init script to run before ssh and regenerate the ssh + host kes in the init script rather than /etc/rc.local (LP: #370628) + * ec2-set-apt-sources.py: + - Move sources.list to /var/ec2 so it doesnt get removed after user + reboots. + * ec2-set-defaults.py: + - Move locale to /var/ec2/ so it doesnt get remove after user reboots. + * ec2-set-hostname.py + - Create an /etc/hostname as well. + + -- Chuck Short Thu, 14 May 2009 11:11:49 -0400 + +ec2-init (0.3.4ubuntu2) karmic; urgency=low + + * Really change the locale when setting up an instance. (LP: #341066) + * Run ec2-run-user-data script last. (LP: #373055) + * Minor comment tweaks. (LP: #373057) + + -- Chuck Short Wed, 13 May 2009 13:41:35 -0400 + +ec2-init (0.3.4ubuntu1) karmic; urgency=low + + * Add more smarts to ec2 instance bring up. (LP: #371936) + + -- Chuck Short Tue, 05 May 2009 08:59:54 -0400 + +ec2-init (0.3.3ubuntu12) jaunty; urgency=low + + * ec2-run-user-data.py: Fix error. + + -- Chuck Short Tue, 07 Apr 2009 08:14:07 -0400 + +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 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) + + -- Chuck Short Wed, 01 Apr 2009 08:48:05 -0400 + +ec2-init (0.3.3ubuntu9) jaunty; urgency=low + + * ec2-set-apt-sources.py: + - Use a template to generate the sources.list and generate it based on the lsb_release. + + -- Chuck Short Tue, 31 Mar 2009 15:15:55 -0400 + +ec2-init (0.3.3ubuntu8) jaunty; urgency=low + + * ec2-set-apt-sources.py: + - Add the ubuntu-on-ec2 ppa. + + -- Chuck Short Tue, 31 Mar 2009 09:37:13 -0400 + +ec2-init (0.3.3ubuntu7) jaunty; urgency=low + + * debian/rules: Fix typo. + + -- Chuck Short Sun, 22 Mar 2009 17:14:16 -0400 + +ec2-init (0.3.3ubuntu6) jaunty; urgency=low + + * Set the configuration file to jaunty. + * ec2-fetch-credentials: Fix typo. + * ec2-set-defaults.py: + - Remove timezone change when booting the instance. + - Redirect output to /dev/null. + * ec2-set-apt-sources.py: + - Run apt-get update after the /etc/apt/sources.list and + redirect the output to /dev/null. + * rightscale-init: Updated rightscale-init + + -- Chuck Short Thu, 19 Mar 2009 20:52:59 -0400 + +ec2-init (0.3.3ubuntu5) jaunty; urgency=low + + * debian/ec2-config.cfg: + - Add disable root option. + * debian/ec2-init.rightscale-init.init: + - Add rightscale detection script. + * ec2-get-info.py: + - Display the information about an AMI instance. + + -- Chuck Short Mon, 16 Mar 2009 08:54:49 -0400 + +ec2-init (0.3.3ubuntu4) jaunty; urgency=low + + * ec2-fetch-credentials.py: + - Allow user to choose which user they wish to configure for. + - Allow user to disable root user if they wish to. + * ec2-set-defaults.py: + - Set default timezone to UTC. + - Set locale depending on zone. + * debian/init: + - Removed nash plugin. + - Add ec2-set-defaults. + + -- Chuck Short Wed, 04 Mar 2009 08:33:01 -0500 + +ec2-init (0.3.3ubuntu3~intrepid4) intrepid; urgency=low + + * set distro to intrepid. + + -- Chuck Short Thu, 26 Feb 2009 10:28:06 -0500 + +ec2-init (0.3.3ubuntu3) jaunty; urgency=low + + * debian/ec2-init: Log results of ec2-run-user-data to syslog. + * ec2-run-user-data.py :Dont leave files around and log the + output to syslog. + + -- Chuck Short Thu, 26 Feb 2009 10:24:35 -0500 + +ec2-init (0.3.3ubuntu2) jaunty; urgency=low + + * ec2-set-apt-sources.py: + - Use the ec2 mirrors. (LP: #317065, #333897) + - Update the /etc/apt/sources.list (LP: #333904) + * ec2-fetch-credentials.py: + - Better error checking (LP: #325067) + + -- Chuck Short Tue, 24 Feb 2009 14:02:37 -0500 + +ec2-init (0.3.3ubuntu1) jaunty; urgency=low + + * debian/init: Fix init script. + + -- Chuck Short Fri, 20 Feb 2009 09:22:54 -0500 + +ec2-init (0.3.3) jaunty; urgency=low + + * ec2-set-apt-sources.py + - Determine the zone that the user is in and generate + a /etc/apt/sources.list.d/ based on that. + * debian/init: + - Check to see if there is an /var/run/ec2 and create + it if it doesnt exist. + - Start ec2-set-apt-sources at first bootup. + * debian/rules: + - Install ec2-set-apt-sources. + * debian/control: + - Add python-configobj as a dependency. + * debian/{install,dirs} + - Create an /etc/ec2-init to read the configuration file and install it. + + -- Chuck Short Mon, 09 Feb 2009 10:35:56 -0500 + +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 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. + * debian/rules: Start ec2-init after ssh. + * ec2-run-user-data.py: Save run-user-data script with ami-id. + + -- Chuck Short Mon, 26 Jan 2009 10:40:52 -0500 + +ec2-init (0.3) jaunty; urgency=low + + * ec2-run-user-data: Fix python error when writing a file to the disk. + + -- Chuck Short Thu, 15 Jan 2009 11:49:08 -0500 + +ec2-init (0.2) jaunty; urgency=low + + * debian/init: Run fetch-credentials before anything else. + (LP: #308533) + * Add ec2-set-hostname.py: Queries ec2 metdada for public-hostname + and then sets it (LP: #316201) + + -- Chuck Short Tue, 13 Jan 2009 15:20:21 -0500 + +ec2-init (0.1) intrepid; urgency=low + + * Initial release (LP: #269434). + + -- Soren Hansen Fri, 12 Sep 2008 15:30:32 +0200 +