UbuntuCloudForDev

- Start Ubuntu instance - Should have enough space on root directory
- To remove the Perl locale warnings
# locale-gen en_US en_US.UTF-8
then
# dpkg-reconfigure locales
- tasksel
- Select Ubuntu Desktop

- Add multiverse repositories
imon@ubuntu:~$ cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu jaunty main
deb http://security.ubuntu.com/ubuntu jaunty-security main

deb http://gb.archive.ubuntu.com/ubuntu/ jaunty universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty universe

deb http://gb.archive.ubuntu.com/ubuntu/ jaunty multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty multiverse

- Install tightvncserver
sudo aptitude install tightvncserver

- Create imon user
useradd imon -m -s /bin/bash
passwd

- su imon
- cd
- mkdir .vnc
- vi .vnc/xstartup

Paste in .vnc/xstartup
imon@ubuntu:~$ cat .vnc/xstartup
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1 # the fix
gnome-session &

- chmod +x .vnc/xstartup

# To fix the keyboard layout bug
gconftool --set /desktop/gnome/peripherals/keyboard/kbd/layouts --type List --list-type String [aa]

- tightvncserver -depth 24 -geometry 1152x864 :1 ( to start on DISPLAY 1)
- tightvncserver -kill :1 ( to kill the vnc server)

Client
<public ip address>:<DISPLAY> -> <ip>:1
Make sure that you have port 5900 + <DISPLAY> open -> eg. ec2auth default -Ptcp -p5901

Setup Dev environment
# Setup Bashrc file
export ROOT_HOME=/mnt
export MVN_HOME=$ROOT_HOME/softwares/springsource/maven-3.0.3.RELEASE
export PATH=$MVN_HOME/bin:$PATH

# Install Java and Subversion
sudo aptitude install sun-java6-jre sun-java6-jdk
sudo aptitude install subversion

# create pre-req directories
sudo chown -R imon:imon /mnt
mkdir -p /mnt/setup
mkdir -p /mnt/softwares
mkdir -p /mnt/workspace
mkdir -p /mnt/.m2
mkdir -p /mnt/.ivy2

# Download & Install Springsource
cd /mnt/setup
wget http://download.springsource.com/release/STS/2.5.2/dist/e3.6/springsource-tool-suite-2.5.2.RELEASE-e3.6.1-linux-gtk-x86_64-installer.sh
chmod +x spring<TAB>
./spring<TAB>

# symlinks
ln -s /mnt/.m2 /home/imon/.m2
ln -s /mnt/.ivy2 /home/imon/.ivy2

# setup maven
cd /mnt/softwares/springsource/
wget http://mirror.lividpenguin.com/pub/apache//maven/binaries/apache-maven-3.0.3-bin.tar.gz
tar xf apache-maven-3.0.3-bin.tar.gz
rm apache-maven-3.0.3-bin.tar.gz
mv apache-maven-3.0.3 maven-3.0.3.RELEASE

# Checkout Beaconflow
cd /mnt/workspace/
svn co https://collaborate.bt.com/svn/cloudservices-koala/branches/beaconflow beaconflow

[Curl] CLI Examples

COUPON

/coupon - creates coupon request for early access (pass in email) - <b>Note: This resource does not use base api url

curl -X POST -d "email=chris@nodester.com" http://localhost:8080/coupon

 

STATUS

/status - returns status of the platform and number of nodejs apps running

// curl http://api.localhost:8080/status

 

USER

/user - creates user account (pass in user and password and email) - Note: This resource does not use the api subdomain

curl -X POST -d "user=testuser&password=123&email=chris@nodester.com" http://localhost:8080/user

 

/user - delete user account (requires basic auth)

curl -X DELETE -u "testuser:123" http://api.localhost:8080/user

 

APP

/app - create nodejs app for hosting (requires basic auth and returns the port address required for use along with a git repo to push to)

curl -X POST -u "testuser:123" -d "appname=a&start=hello.js" http://api.localhost:8080/app

 

Get information about an app

curl -u "testuser:123" http://api.localhost:8080/app/a

 

Start or stop an app using running=true|false

curl -X POST -u "testuser:123" -d "appname=a&running=true" http://api.localhost:8080/app

curl -X POST -u "testuser:123" -d "appname=a&running=false" http://api.localhost:8080/app

 

/app - update nodejs app for hosting (requires basic auth, appname, and starting page and returns the port address required for use along with a git repo to push to)

curl -X PUT -u "testuser:123" -d "appname=a&start=hello1.js" http://api.localhost:8080/app

 

/app - delete nodejs app (requires basic auth and appname)

curl -X DELETE -u "testuser:123" -d "appname=test" http://api.localhost:8080/app

 

/app - get nodejs app info (requires basic auth and appname)

curl -u "testuser:123" http://api.localhost:8080/app/appname

 

/apps - get all your apps info (requires basic auth)

curl -u "testuser:123" http://api.localhost:8080/apps

 

/appnpm - install, update and uninstall npm packages to your application

curl -X POST -u "testuser:123" -d "appname=a&action=install&package=express" http://api.localhost:8080/appnpm

Setup Python, easy_install, web2py

#Setup Python, easy_install 
yum install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel
tar xf Python-2.7.1.tgz
cd Python-2.7.1
./configure --prefix=/opt/python-2.7.1
make
make install
cd ..

# Install setup tools
PATH=/opt/python-2.7.1/bin:$PATH sh setuptools-0.6c11-py2.7.egg
rm setuptools-0.6c11-py2.7.egg

# Setup web2py
unzip web2py_src.zip
rm web2py_src.zip

Spring STS direct downloads

Setting up VNC for Ubuntu server

1. Install image
1.5. tasksel -> Install Ubuntu desktop
2. Update sources.list

imon@ubuntu:~$ cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu jaunty-updates main
deb http://archive.ubuntu.com/ubuntu jaunty-updates universe
deb http://security.ubuntu.com/ubuntu jaunty-security main

3. sudo aptitude update
4. sudo aptitude -y upgrade

5. 

root@ubuntu:~# aptitude -y install vnc4server 

root@ubuntu:~# vi /etc/vnc.conf 

# create new
$geometry = "1024x768";
$depth = "24";

root@ubuntu:~# su - lucid # switch to a user who set VNC
lucid@ubuntu:~$ vncpasswd # set VNC password
Password:# input
Verify:
lucid@ubuntu:~$ vncserver # start
xauth: creating new authority file /home/lucid/.Xauthority

New 'ubuntu:1 (lucid)' desktop is ubuntu:1

Creating default startup script /home/lucid/.vnc/xstartup
Starting applications specified in /home/lucid/.vnc/xstartup
Log file is /home/lucid/.vnc/ubuntu:1.log

lucid@ubuntu:~$ vi .vnc/xstartup 

# add lines
exec gnome-session &

lucid@ubuntu:~$ vncserver -kill :1 # stop
Killing Xvnc4 process ID 31104
lucid@ubuntu:~$ vncserver # start

New 'ubuntu:1 (lucid)' desktop is ubuntu:1

Starting applications specified in /home/lucid/.vnc/xstartup
Log file is /home/lucid/.vnc/ubuntu:1.log

Node workshop

rm -rf /opt/*
yum install gcc-c++ openssl-devel
tar xf node*
cd node*
./configure --prefix /opt/nodejs
make
make install
ln -s /opt/nodejs/bin/node /usr/local/bin

sudo chown -R $USER /usr/local
curl http://npmjs.org/install.sh | sh 

vim simple_server.js

var http = require('http');

http.createServer(function (req, res) {
  console.log("Received request:" + req);
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('<b>Hello World</b>\n');
}).listen(8080);

console.log('Server running at http://127.0.0.1:8080/')

node simple_server.js

<Make sure that port 8080 is open>

Add file system

var http = require('http')
var url = require('url')
var fs = require('fs')

var port = 8080

var server = http.createServer(function(req, res) {
        var path = url.parse(req.url).pathname;

        if (path == '/') {
                path = '/index.html'
        }

        console.log("serving:" + path);

        fs.readFile(__dirname + path, function(err, data) {
                if (err) {
                        res.writeHead(404);
                        res.end();
                } else {
                        res.writeHead(200, {'Content-Type': contentType(path)});
                        res.write(data, 'utf8');
                        res.end();
                }
        });

});

function contentType(path) {
        if (path.match('.js$')) {
                return "text/javascript";
        } else if (path.match('.css$')) {
                return "text/css";
        } else {
                return "text/html";
        }
}

server.listen(port);
console.log("HTTP Server listening on " + port);