Archive for the ‘Uncategorized’ Category.

AWS server migration/scaleup (debian)

I’m using AWS (EC2) for a lot of my work at the moment, I generally run things out of a microinstance, however sometimes I need to scaleup to a larger system to run something computationally intensive. I’m using debian, and this is the script I’m currently using to do this. You’ll need to setup euca-tools, and have .eucarc files for the regions you want to use, but this might help point you in the right direction:

#!/bin/bash

# Region select
REGION=EU
echo $REGION

#for new regions you need to:
#euca-add-keypair keypair_for_regular_debian_machine > keypair_private_$REGION.asc_complete
#chmod 0600 keypair_private_$REGION.asc_complete

cd ~
cp .eucarc_eu .eucarc

# start instance
if [ "$REGION" == "EU" ]
then
  euca-run-instances --instance-type m1.xlarge ami-8992a5fd -k keypair_for_regular_debian_machine
fi

if [ "$REGION" == "JP" ]
then
  echo "JP"
  euca-run-instances --instance-type m1.xlarge ami-22a80223 -k keypair_for_regular_debian_machine
fi

sleep 30

# setup remote system
export NEWSERVER=`euca-describe-instances | tail -n 1 | awk '{print $4}'`
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER useradd --shell /bin/bash new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER mkdir  /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER chowan new:users /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER chmod 777 /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER apt-get update
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER apt-get -y install make g++ vim gnuplot unison
scp -oStrictHostKeyChecking=no -r -i keypair_private_$REGION.asc_complete /home/new root@$NEWSERVER:/home/new

iOS SDL 1.3 (SDL2) rotation on iOS causes screen offset.

I was having an issue with SDL on iOS (6). Whenever I rotated the screen rather than changing the orientation the rendering area seemed to stay where it was. This manifested itself as the origin appearing offset to the left of (-100 odd pixels) and below (+100 odd pixels) from the true origin.

This turned out to be an issue with the Rendering context. When the screen is rotated the UIKit SDL interface creates a new OpenGL rendering context, and this is what you should write to… However, turns out you can happily keep writing to your old context and it well be renderered, just in the wrong orientation. So this is what you have to do in your event loop:

if (event->type == SDL_WINDOWEVENT && (event->window.event == SDL_WINDOWEVENT_RESIZED) || (event->window.event == SDL_WINDOWEVENT_RESTORED)) {
    SDL_GetWindowSize(screen,&display_width,&display_height);
    SDL_DestroyRenderer(renderer);
    renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);
    function_to_trash_all_SDL_Textures();
    SDL_StartTextInput();

    SDL_RaiseWindow(screen); // probably not required.
}

As you can see in addition to trashing the Renderer you will need to re-enable TextInput if you’re using it. All textures you’ve previously created will also be invalidated, you therefore need to delete and reinitialise them. I’m guess this means rotating the screen and be a significant overhead.

UPDATE: You also need to check for SDL_WINDOWEVENT_RESTORED this is used when the app wakes up from going into the background the renderer context can also become invalid in these situations.

iPhone SDL 1.3 (SDL2) keyboard disappearing and misregistration issues.

I was having a couple of issues with the SDL keyboard on the iPhone. The first was that the keyboard disappears when you press enter, I didn’t want this. So I made the following change to SDL_uikitview.m:

/* Terminates the editing session */
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
{
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
    //SDL_StopTextInput();
    return YES;
}

However once I did this I was /sometimes/ getting the return key misregistering as either p or l. I found changing the keyboard for U.S. English to another language and then back again fixed the issue for the rest of the apps execution. The hack round this I finally put in place was to restart the TextInput in this method as follows:

/* Terminates the editing session */
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
{
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
    SDL_StopTextInput();
    SDL_StartTextInput();
    return YES;
}

FAI on Ubuntu 12.04

These notes are a work in progress and detail my installation of FAI (Fully Automatic Installation) on Ubuntu 12.04. I had some issues before realising I needed a 64bit client to install to (had PXE working then realised my client is 32bit only). This is worth noting as it’s most likely /VERY/ annoying to build a FAI server for a different architecture.

Also, be careful about doing this on an active network, as you can easily setup a rogue DHCP server which will make bad things happen.

Install the basic FAI packages:

apt-get install fai-quickstart

Add the following to /etc/exports:

/srv/fai/config (async,ro,no_subtree_check,no_root_squash)

Edit: /etc/fai/make-fai-nfsroot.conf

Change: FAI_DEBOOTSTRAP="squeeze http://cdn.debian.net/debian"
To    : FAI_DEBOOTSTRAP="precise http://gb.archive.ubuntu.com/ubuntu"

Do the initial debbootstrap, copy the sample dhcp server config into place.

sudo fai-setup
/etc/init.d/nfs-kernel-server reload
apt-get install isc-dhcp-server syslinux-common tftpd-hpa
cp /usr/share/doc/fai-doc/examples/etc/dhcpd.conf /etc/dhcp/dhcpd.conf

add hosts to /etc/dhcp/dhcpd.conf similar to the example line already present:

host demohost {hardware ethernet 0:2:a3:b5:c5:41;fixed-address demohost;}

or remove:

deny unknown-clients;

to allow all clients

add a range if required under the subnet line, e.g.:

range 192.168.1.1 192.168.1.50;

edit /etc/default/tftpd-hpa:

CHANGE: TFTP_DIRECTORY="/var/lib/tftpboot"
TO    : TFTP_DIRECTORY="/srv/tftp"

and/or add the following in /etc/init/tftpd-hpa.conf :

env TFTP_DIRECTORY="/srv/tftp"

Install demo configuration files (this may not be required):

cp -a /usr/share/doc/fai-doc/examples/simple/* /srv/fai/config

Set permissions on kernel correctly:

chmod o+r /srv/tftp/fai/vmlinuz-3.2.0-36-generic

Edit: /srv/fai/config/files/boot/grub/menu.lst/postinst

Comment out as follows:

#$ROOTCMD grub-install --no-floppy $(device2grub $BOOT_DEVICE)

Edit, /srv/fai/config/scripts/GRUB/10-setup replace the entire contents as follows:

#! /bin/bash

error=0 ; trap "error=$((error|1))" ERR

# Eventual source the disk_var.sh just in case 
# the BOOT_DEVICE/BOOT_PARTITION/ROOT_PARTITION 
# variables are overwritten
[ -r /tmp/fai/disk_var.sh ] && . /tmp/fai/disk_var.sh

ifclass NOMBR && BOOT_DEVICE=$BOOT_PARTITION

[ -z "$BOOT_DEVICE" ]    && exit 701
[ -z "$BOOT_PARTITION" ] && exit 702

# call grub-install from ubuntu
$target/usr/sbin/grub-install --no-floppy --root-directory=/$target $BOOT_DEVICE

# call update-grub inside ubuntu chroot with special "no user questions" flag
$ROOTCMD /usr/sbin/update-grub -y

exit $error

Create: /srv/tftp/fai/pxelinux.cfg/default with the following contents:
Note, this currently boots to fai then tries to connect to the nfs server.

       # Default boot option to use
       DEFAULT x64

       # Prompt user for selection
       PROMPT 0
       # Menu Configuration
       MENU WIDTH 80
       MENU MARGIN 10
       MENU PASSWORDMARGIN 3
       MENU ROWS 12
       MENU TABMSGROW 18
       MENU CMDLINEROW 18
       MENU ENDROW 24
       MENU PASSWORDROW 11
       MENU TIMEOUTROW 20
       MENU TITLE Main Menu
       # Menus
       LABEL x64
         MENU LABEL x64
         KERNEL vmlinuz-3.2.0-36-generic
         APPEND initrd=initrd.img-3.2.0-36-generic ip=dhcp root=/dev/nfs nfsroot=/srv/fai/nfsroot boot=live FAI_FLAGS=verbose,sshd,createvt FAI_ACTION=install FAI_CONFIG_SRC=nfs://192.168.1.100/srv/fai/config

This config installs an Ubuntu system for me, but there appear to be bootloader issues (hopefully resolved now, testing).