Linux Xen Notes

Quick and dirty ref sheet for myself 🙂

vgdisplay – this command shows you all the disk space used/free
lvdisplay – this will show you all the partitions that you have running and how big they are etc

lvextend -L +10G /dev/vg00/files – this will increase /dev/vg0/files 10GB
xfs_growfs /dev/vg0/files – this will resize the xfs partition to take into account eh extra 10GB

lvcreate /dev/vg0 -n mail1 -L 10G # create a partition 10GB called mail1
  lvcreate /dev/vg0 -n mail1-swap -L 1G # create a partition 1GB called mail1-swap
  mkswap /dev/vg0/mail1-swap
  xen-create-image --dist=sarge --debootstrap --hostname=mail1 --force --passwd --size=10G --swap=1G --lvm=vg00   --mirror=http://ftp.nz.debian.org/debian/ --mem=200 --gateway=192.168.10.2 --netmask=255.255.255.0 --ip=192.168.10.81
  cd /etc/xen/ # make a config/copy one from elsewhere and edit it
  sudo ln -s /etc/xen/mail1.cfg /etc/xen/auto/
  xm create -c mail1.cfg
  xm console mail1

Terminology: In xen, everything runs as a virtual machine, even the ‘host operating system’ ( called dom0 ) is just the virtual machine from which you control all the others. The ‘virtual machines’ themselves are called ‘domU’ virtual machines & the only difference is their absence of this admin capability.

To do anything with Xen, ssh to the dom0 on which your xen domU runs and run the ‘xm’ xommand

xm #Lists xm subcommands
xm list # lists xen domUs
xm top # Show xen CPU usage
xm reboot xxxxx #Reboot xen nodes
xm shutdown xxxx # shutdown xen node
xm destry xxxx # equivalent of pulling power cable
xm create xxxx.cfg #Boot a xen node (note the cfg)
xm console xxx # Attach to the console of a xen node, press CTRL-] to exit

To create a xen machine try a shell script similar to this

hostname=test
dist=sarge # Or etch for a new system
ipaddress=192.168.10.161
mem=2000
xen-create-image --dist=$dist --debootstrap --hostname=$hostname --force --passwd --size=5G --swap=1G --lvm=vg00   --mirror=http://debian.orcon.net.nz/debian --mem=$mem --gateway=192.168.10.2 --netmask=255.255.255.0 --fs=xfs --ip=$ipaddress

PHP Code

General:
– code as if whoever maintains your code is a violent psychopath who knows where you live
– code in paragraphs, i.e. group related chunks and separate them by a new line
– indent style uses the K & R style
– columns 100 max, unless workaround (i.e. HTML) is needed
– The use of <?php ?> to delimit PHP code is encouraged, especially for core packages
– Using <? ?> is OK for main PHP files

File Format:
– use the UNIX file format, that is a LF character for end of lines
– make sure there is no whitespace after the last non whitespace character for every line

Comments:
– avoid // for comments in PHP
– comments should start with #
– /* */ style in PHP is OK for multiple lines
– when commenting out code lines add the comment character at the start of the line,
makes it easier to separate form normal comments,

Tabs:
– tab indent size should be set to 4
– tabs should be used for identing only NOT for alignment
– a tab character can only be used at the start of the before any non-whitespace character
– checkout the Smart Tabs vim plugin

function do_something() {
<TAB>$long_variable = foo($baz);
<TAB>$short = foo($bar);
^^^^^^^^^
space
}

Identifiers:
– abbreviations should be avoided, ie $session->initialise() not $session->init()
– common abbreviations are acceptable as long as they are used the same way throughout the project.

Vars:
– hungarian notation is to be avoided for scripting languages
– use all lower case letters separated with underscores, i.e. $first_name
– space on each sides of equal for assignment, i.e. $first_name = ‘John’;

Hashes & Associative Arrays:
– in Perl both $hash{key} and $hash{‘key’} are OK
– in PHP both $array[key] and $array[‘key’] are OK

Constants:
– all uppercase separated by underscores, eg SESSION_TIMEOUT
– in Perl use Readonly instead of constant
– for PHP constants related to a class, prefix with the name of the class they are used in.
for example, the constants used by the Benon_DB package should all begin with “Benon_DB_”.

Strings:
– avoid using double quotes unless necessary
– only simple variables are allowed in an interpolated string
– do not use hashes, arrays, ${var} expressions in interpolated strings

$var = ‘My String’;
$associative_array[‘key’];
$var = “…string… $some_var …more…’.$another_var.’_more stuff…’;
$var = “…string…’.$another_var.’_more stuff…’;
$sql = ‘INSERT INTO mytable (field) VALUES (‘.$db->quote($var).’)’;
$var = “My String\n”;

Control:
– one space on each side of the brackets

for ($i; $i < 10; $i++) {
# …
}

foreach ($arr as $k => $v) {
# …
}

while ($i < 10) {
# …
}

Tests:
– one space on each side of the brackets
– uncuddled elses: return line after a closing curly bracket
– only “if (…) do_something” in ONE line are allowed

if ($a == $b) {
# …
}
elsif ($a == 1) {
# …
}
else {
# …
}

Functions:
– use all lower case words separated by and underscore
– follow the verb/subject rule, ie get_this, do_something, is_ready
– use a space between the function/sub keyword and the identifier
– use arrays as arguments for public functions in core packages
– use PHPdoc http://manual.phpdoc.org

function print_name($first, $last) {
echo $var;
}

foo(‘John’, ‘Doe’);
foo(array(first => ‘John’, two => ‘Doe’));
foo(array(
first => ‘John’,
two => ‘Doe’
));

Classes:
– use CamelCase, i.e. SomeNamespace::SomePackage
– In PHP use an underscore to fake namespace separation, i.e. SomeNamespace_SomePackage
Hopefully one day PHP devs will get a clue and support namespaces 🙂
– For PHP constructors, use __construct not the name of the package
– abreviations are left uppercase, ie “DB” not “Db”, i.e. Benon_DB_Result

SQL:
– keywords all uppercase, ie SELECT FROM blah WHERE name = ‘Joe’;

Linux and I

Okay, most people probably realize that Linux and I have this thing going on.

My first computer was a 486 dx100 with 16mb ram and 150mb HDD. The dude who made it for me installed windows 98 Beta and absolutly no drivers. His Win 95 cd had stopped working apparently.

So the hard drive was double spaced to fit it so 300mb. I had about 20mb free at any one time and spent hours removing temporary files a day. I had a single mp3, because there simply wasnt room for more. My modem was my sisters 14.4 i think (or was it 9600?).

Everything i saw was in 16 colours until one day i right clicked on the desktop to change wallpaper and realized i could change it!.

debian_logo.gifSo within 9 months later i had mastered IRC and starting programming mIRC. I loved the idea of code and being able to program everything. A dude i knew with the nickname theGeek (its now steviant) took time out to come over and install redhat linux once. By this point I think I had upgraded to a low end Pentium machine with everything on-board.
I promptly lost my root password, and three weeks later managed to dialup from it, get another friend to rootkit me and change my password to 819P3N15 (thanks nitro- , always loved big penis!).
Anyway i got the hang of it pretty quick. Moved onto Slackware 4.0 when it was released.
About the same time i met Paul (who is now, 7 years later, my husband) who also used Linux, though not to the extent i did (i totally ditched windows fairly early on).
He tought me a fair bit as well, and eventually due to time constraints and children i moved on to using Debian.
Ive worked in the IT industry since pretty much 6 months of touching linux installing servers, setting up a couple of ISPs, and doing mostly server work.
slackwareLogo.JPGAbout 4 years ago i got sick of the hours doing servers and moved back into programming side. I do mostly web based code now (php, perl, etc), though I still maintain my own servers and fix others on occasion.

Ive been apparently owning #NZLinux on undernet, an IRC channel for about 7 years also, though its generally everyone has access and there are rarely fights or arguments.

Umm all the kids are familiar with linux, mac, and windows. None appear to have much preference other than the oldest who plays games.

My bestest friend Miriam uses linux and shes most definatly not a geek, but it suits her and the boys as they cant break it and it rarely needs a reinstall 🙂