Tim Dysinger RSS

Apr
27th
Sun
permalink

Public Ubuntu Hardy Amazon EC2 Image (AMI) Now Available

I have prepared a new Ubuntu Hardy Amazon AMI image(s). They are in my ubuntu-ami bucket. I'll start with a "small" ec2 instance image. The public AMI is "ami-4f7a9f26". It is meant to be started with AKI "aki-9b00e5f2" (which comes with fuse). The image is a bare-bones ubuntu hardy standard install. You can update it with the software you need. I will have 64-bit versions available early next week. The emphasis on my images is clean and tidy. I don't install a bunch of crud that you may or may not need. It's just the basics with a userdata-boot-hook (give the image a bash script at boot-time as userdata). Here is how I created the image:

# Bootstrap
mkdir /mnt/ubuntu
debootstrap --arch i386 hardy /mnt/ubuntu

# Start
cat /proc/mounts >/mnt/ubuntu/etc/mtab
mount -o rbind /proc /mnt/ubuntu/proc
mount -o rbind /dev /mnt/ubuntu/dev
mount -o rbind /sys /mnt/ubuntu/sys
cat /etc/resolv.conf >/mnt/ubuntu/etc/resolv.conf
chroot /mnt/ubuntu /bin/bash

# Hostname
echo '127.0.0.1 localhost' >/etc/hosts

# Tidy
rm -rf tmp && ln -sf var/tmp tmp
rm -rf opt && ln -sf usr/local opt

# Locale
localedef -i en_US -c -f UTF-8 en_US.UTF-8
echo 'LANG="en_US.UTF-8"' >/etc/default/locale

# Update
cat >/etc/apt/sources.list < <\EOF
deb http://us.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
EOF
gpg --keyserver wwwkeys.pgp.net --recv-keys A70DAF536070D3A1
gpg --armor --export A70DAF536070D3A1  apt-key add -
cat >/etc/apt/sources.list.d/debian.list < <\EOF
deb http://http.us.debian.org/debian/ unstable main contrib non-free
deb-src http://http.us.debian.org/debian/ unstable main contrib non-free
deb http://http.us.debian.org/debian/ experimental main contrib non-free
deb-src http://http.us.debian.org/debian/ experimental main contrib non-free
EOF
cat >/etc/apt/apt.conf < <\EOF
APT::Default-Release "hardy";
EOF
apt-get update
apt-get install -y libc6-xen
rm -rf /lib/tls
apt-get upgrade -y
apt-get install -y ubuntu-standard

# Modules
wget -O - \
  http://s3.amazonaws.com/ec2-downloads/ec2-modules-2.6.18-xenU-ec2-v1.0-i686.tgz  \
  tar --no-same-owner -xzC /
depmod -a
echo 'loop' >>/etc/modules

# Color
perl -p -i -e 's/xterm-color/xterm\*color/g' /etc/skel/.bashrc ~/.bashrc
apt-get install -y ncurses-term

# TTY
rm -f /etc/event.d/tty[2-6]

# Network
shadowconfig on
usermod -p \
  `dd if=/dev/urandom count=50 2> /dev/null  md5sum  cut -d " " -f1-1` \
  root
mkdir /etc/skel/.ssh
chmod 600 /etc/skel/.ssh
cp -r /etc/skel/.ssh /root
apt-get install -y ntp openssh-server
cat >/etc/ssh/sshd_config < <\EOF
Protocol 2
StrictModes yes
MaxStartups 10:30:60
Ciphers aes256-cbc,aes256-ctr
PasswordAuthentication no
ChallengeResponseAuthentication no
Subsystem sftp /usr/lib/openssh/sftp-server
UseDNS no
EOF
cat >/etc/network/interfaces < <\EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF

# Boot
cat >/etc/rc.local < <\EOF
#!/bin/sh -e
# Root SSH Public Key
mkdir -p /root/.ssh >/dev/null 2>&1
wget -q -O - http://169.254.169.254/2008-02-01/meta-data/public-keys/0/openssh-key \
  >/root/.ssh/authorized_keys
chmod -R go-rwsx /root
# Userdata Shell Script
wget -q -O - http://169.254.169.254/2008-02-01/user-data  sh
exit 0
EOF

# Fstab
cat >/etc/fstab < <\EOF
/dev/sda1 /    ext3 user_xattr 0 1
/dev/sda2 /mnt ext3 user_xattr 0 2
/dev/sda3 swap swap sw         0 0
EOF

# EC2 tools
apt-get install -y symlinks unzip ruby libopenssl-ruby1.8 curl ca-certificates
cd /tmp
wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
cd /usr/local
unzip /tmp/ec2-ami-tools.zip
ln -sf `find . -type d -name ec2-ami-tools*` ec2-ami-tools
chmod -R go-rwsx ec2*
rm -rf /tmp/ec2*

# Bundle
rm /bin/sh && ln -s /bin/bash /bin/sh ; # make bash the default for ec2
modprobe loop ; # bundle image needs this
cat >/usr/local/sbin/image < <\EOF
#!/bin/bash
export EC2_AMITOOL_HOME=/usr/local/ec2-ami-tools
PATH=$EC2_AMITOOL_HOME/bin:$PATH
BUNDLE=`date '+%y%m%d%H%M%S'`
ec2-bundle-vol -r i386 -u $AMAZON_USER_ID --fstab /etc/fstab \
  -k $EC2_PRIVATE_KEY -c $EC2_CERT -b -d /mnt -s 10240 -e /root/.ssh -p $BUNDLE
ec2-upload-bundle -b $HOSTNAME -m /mnt/$BUNDLE.manifest.xml \
  -a $AMAZON_ACCESS_KEY_ID -s $AMAZON_SECRET_ACCESS_KEY
rm -rf /mnt/$BUNDLE* /mnt/img-mnt
EOF
chmod 700 /usr/local/sbin/image

export HOSTNAME=ubuntu-ami
apt-get clean
apt-get autoclean
apt-get autoremove
symlinks -cdrsv /
rm -rf /var/tmp/* ~/.bash_history
image

# Register & make the ami public (on another machine)
ec2-register $HOSTNAME/XXXXXXXXXXXXX.manifest.xml
ec2-modify-image-attribute ami-XXXXXXX --launch-permission -a all

# Run
ec2-run-instances \
  -K ~/.amazon/pk.pem -C ~/.amazon/cert.pem \
  -k mykey --kernel aki-9b00e5f2 \
  ami-XXXXXXXXXXX
Apr
25th
Fri
permalink

Dmitri Gaskin Rocks

Kids amaze me. Here's a video of Dmitri Gaskin giving a Google Tech Talk on JQuery. Good job Dmitri! You remind me of myself when I was 12 except, when I was a kid, 6502 assembly language and Commodore's where the in thing for kids and not web-programming. The only problem I have with Dmitri is that he likes PHP and Drupal. He's only 12 though. He'll grow out of it... :)
permalink

Rack: An API for Web Servers and Ruby Frameworks

In today's ruby web application landscape, every framework developer is writing his/her own handlers for every server he/she wants to support. This results in semi-duplicate code, if not for the web-server developer then for the framework-developer. This is the pain-point that Rack aims to solve. Rack proposes "why not have some common ground?" Java did this with the Servlet API 10 years ago. Python did this with WSGI 5 years ago. By leveraging Rack, framework developers and web-server developers gain access to one another without having to write special adapters. Today that's WEBrick, Mongrel, CGI, Ebb, Fuzed & Thin for web-servers and Rails, Camping, Coset, Halcyon, Maveric, Merb, Racktools::SimpleApplication, Ramaze, Sinatra & Vintage for web-frameworks. (this will undoubtably be outdated by conference time). Tomorrow every new web-server and web-framework that supports Rack can be used together. You'll be able to pick and choose the best web-server for you without changing your favorite web-framework and vice-versa. "What do Rails developers really stand to gain today by leveraging Rack?" It might be the ability to run several "rackable" applications side by side inside a single web-server instance. It might be the possibility to leverage or stack applications. You can intercept requests, modify them and pass them through to other handlers. You can also have multiple rackable applications sitting next to each other that comprise one user-facing application. Don't like file uploads with Rails? Use another web framework or the Rack API directly to write it and place it along side your Rails app in the same application. Want to use single-sign-on for 3 Rails apps? No problem. Rack makes it easy to tie apps together. Rack Hello World ( gem install rack & mongrel & visit http://localhost:3000 )

%w(rubygems rack).each { dep require dep }
Rack::Handler::Mongrel.run(
  lambda { e [
      301,
      { 'Location' => 'http://rubyurl.com/g6L' },
      ':P'
    ]
  },
  :Port => 3000
)
Apr
22nd
Tue
permalink

Karma Yoga in Software Engineering

I work in software development and it is a very competitive business. At times I have to catch myself, when I feel an emotion, and ask myself "Why?". Why am I being competitive? Why am I seeking recognition? Why am I wanting control? Is my argument on the design the best for the team? Are my motivations the best for the project? In reading about Karma Yoga, I realize that this is exactly what software developers need to do when writing software. Karma Yoga means "discipline of action" and is based on the teachings of the Bhagwat Geeta, a sacred Sanskrit scripture of Hinduism. Karma Yoga is described as a way of acting, thinking and willing by which one does one's duty without consideration of personal selfish desires, likes or dislikes. Acting without being attached to the fruits of one's deeds. In software this is doing what needs to be done for the betterment of the project and team without attaching your ego and self-worth to the code you write or the contribution you make. When this mindset is taken on by software developers, colloboration, camaraderie and team-work increases while tensions, egos, stress, competition and caustic attitudes decrease. It has to be consciencely chosen, but this is something to be strived for on teams.