Diff for /wikisrc/amazon_ec2.mdwn between versions 1.21 and 1.22

version 1.21, 2011/02/19 02:42:58 version 1.22, 2011/02/19 03:42:54
Line 105  Under */mnt/ec2*, edit the files to add  Line 105  Under */mnt/ec2*, edit the files to add 
 [[!template id=filecontent name=etc/rc.conf text="""  [[!template id=filecontent name=etc/rc.conf text="""
 rc_configured=YES  rc_configured=YES
   
 hostname=NetBSD-EC2-$(uname -m)  
 sshd=YES # for remote shell access to instance  sshd=YES # for remote shell access to instance
 """]]  """]]
   
Line 114  sshd=YES # for remote shell access to in Line 113  sshd=YES # for remote shell access to in
 PermitRootLogin without-password  PermitRootLogin without-password
 """]]  """]]
   
 This file is needed if you want to login via the SSH key pair created previously:  This file is needed if you want to login via the EC2 SSH key pair created previously:
   
 [[!template id=filecontent name=etc/rc.d/ec2-init text="""  [[!template id=filecontent name=etc/rc.d/ec2-init text="""
 #!/bin/sh  #!/bin/sh
Line 129  name="ec2_init" Line 128  name="ec2_init"
 start_cmd="ec2_init"  start_cmd="ec2_init"
 stop_cmd=":"  stop_cmd=":"
   
 SSH_KEY_URL="http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key"  METADATA_URL="http://169.254.169.254/latest/meta-data/"
   SSH_KEY_URL="public-keys/0/openssh-key"
   HOSTNAME_URL="hostname"
   
 SSH_KEY_FILE="/root/.ssh/authorized_keys"  SSH_KEY_FILE="/root/.ssh/authorized_keys"
   
 ec2_init()  ec2_init()
Line 137  ec2_init() Line 139  ec2_init()
         (          (
         umask 022          umask 022
         # fetch the key pair from Amazon Web Services          # fetch the key pair from Amazon Web Services
         EC2_SSH_KEY=$(ftp -o - "$SSH_KEY_URL")          EC2_SSH_KEY=$(ftp -o - "${METADATA_URL}${SSH_KEY_URL}")
   
         if [ -n "$EC2_SSH_KEY" ]; then          if [ -n "$EC2_SSH_KEY" ]; then
                 # A key pair is associated with this instance, add it                  # A key pair is associated with this instance, add it
                 # to root 'authorized_keys' file                  # to root 'authorized_keys' file
                 mkdir -p $(dirname "$SSH_KEY_FILE")                  mkdir -p $(dirname "$SSH_KEY_FILE")
                   touch "$SSH_KEY_FILE"
                 cd $(dirname "$SSH_KEY_FILE")                  cd $(dirname "$SSH_KEY_FILE")
   
                 grep "$EC2_SSH_KEY" "$SSH_KEY_FILE"                  grep -q "$EC2_SSH_KEY" "$SSH_KEY_FILE"
                 if [ $? -eq 0 ]; then                  if [ $? -ne 0 ]; then
                         echo "Setting associated SSH key pair."                          echo "Setting EC2 SSH key pair: ${EC2_SSH_KEY##* }"
                         echo "$EC2_SSH_KEY" >> "$SSH_KEY_FILE"                          echo "$EC2_SSH_KEY" >> "$SSH_KEY_FILE"
                 fi                  fi
         fi          fi
   
           # set hostname
           HOSTNAME=$(ftp -o - "${METADATA_URL}${HOSTNAME_URL}")
           echo "Setting EC2 hostname: ${HOSTNAME}"
           echo "$HOSTNAME" > /etc/myname
           hostname "$HOSTNAME"
         )          )
 }  }
   
   
   load_rc_config $name
   run_rc_command "$1"
 """]]  """]]
   
 Create various files and directories:  Create various files and directories:
Line 161  Create various files and directories: Line 173  Create various files and directories:
 [[!template id=programlisting text="""  [[!template id=programlisting text="""
 cd /mnt/ec2  cd /mnt/ec2
 # Add proc and kern directories  # Add proc and kern directories
 mkdir proc kern  mkdir grub kern proc
 # EC2 network configuration, via DHCP  # EC2 network configuration, via DHCP
 echo "dhcp" > etc/ifconfig.xennet0  echo "dhcp" > etc/ifconfig.xennet0
 # Basic fstab entries  # Basic fstab entries
 cat > etc/fstab << EOF  cat > etc/fstab << EOF
 /dev/xbd1a /        ffs    rw 1 1  /dev/xbd1a /        ffs    rw 1 1
 /dev/xbd0a /grub    ext2   rw 2 2  /dev/xbd0a /grub    ext2fs rw 2 2
 kernfs     /kern    kernfs rw  kernfs     /kern    kernfs rw
 ptyfs      /dev/pts ptyfs  rw  ptyfs      /dev/pts ptyfs  rw
 procfs     /proc    procfs rw  procfs     /proc    procfs rw

Removed from v.1.21  
changed lines
  Added in v.1.22


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb