Archive for the 'Hacks' Category

svnsync with PuTTY on Windows

Objective:

Maintain a copy of my local Subversion repository on my hosting server ready for deployment of my application using Capistrano.

Steps:

  1. Create remote svn repository
  2. Set up svn+ssh using PuTTY on Windows
    1. Download plink.exe and puttygen.exe to you local machine.
    2. run puttygen and generate a public/private key pair
      Don’t set a pass phrase and svn will not prompt you for it later.
    3. Save the private key to keyfile.ppk on your local hard disk.
    4. On the remote host open a file ~/.ssh/authorized_keys and paste in the public key from puttygen.
      Make sure the string fits on a single continuous line.
    5. In the file abov, pre-pend command=”svnserve -t” to the start of the public key.
      This forces the svnserve process to run when ever someone connects using this key pair. Having no passphrase on the key pair isn’t great for security but at least you are restricting access to just svn and not the whole shell.
    6. On the local Windows machine, edit %Application Data%\Subversion\config, under the [tunnels] section add
      [tunnels]
      ssh =plink -i \path\to\keyfile.ppk
      (use back slashes / despite it being on Windows)
    7. Test using svn info svn+ssh://username@host.com/home/username/svn-repos/application
  3. Set up two environment variables to save on the typing
    set torepos=svn+ssh://username@host.com/home/username/svn-repos/application
    set fromrepos=file:///s:/svn-repos
  4. Initialise the synchronisation set up
    svnsync init %torepos% %fromrepos%
  5. Check the synchronisation parameters have been correctly set on the remote repository
    svn proplist –revprop -r 0 %to%
    svn propget svn:sync-from-url –revprop -r 0 %torepos%
  6. Now do the sync
    svnsync sync %torepos%
  7. Sit back and wait, or in my case, go to bed.

Sources of inspiration:

Background Jobs and Queues with Ruby On Rails

http://labnotes.org/cgi-bin/trac.cgi/wiki/Ruby/ReliableMessaging

http://rubyforge.org/projects/backgroundrb/

http://ap4r.rubyforge.org/wiki/wiki.pl?HomePage

http://cleanair.highgroove.com/articles/2006/06/23/running-background-jobs

Ubuntu 704 on VMWare - Increase root partition size

The root partition of my Ubuntu 704 Server Virtual Machine was only 5GB and was filling up regularly. Incresing the size is quite complex as you have to increase the size of the VMWare disk file, then increase the size of the file system partition within the disk file. Here are the steps I went through and a few hints and tips along the way.

1. On the host system, increase size of VMWare disk files

(I added the VMWare folder to my PATH first)

D:\VMWare\ubuntu704server>vmware-vdiskmanager -x 10GB Ubuntu.vmdk

I also changed the file type to dynamically extend (that’s the -t 0), which renames the file in the process. This is an optional step as it can affect the performance of the VM.

D:\VMWare\ubuntu704server>vmware-vdiskmanager -r Ubuntu.vmdk -t 0 Ubuntu-000001.vmdk

2. Download the latest gparted livecd and save to host’s file system

gparted is a GUI tool for manipulating partitions. I tried a number of different tools before the gparted livecd, including qtparted on the latest Knoppix livecd. With the Knoppix qtparted, the resize option was continually greyed out. I did some digging and it seems the underlying parted didn’t like whatever Ubuntu do to the ext3 file system, so any tools on top (such as qtparted) can’t resize. The gparted livecd worked perfectly so I didn’t investigate further.

3. In the VM settings, change the VM’s CDROM to point to the newly downloaded gparted livecd iso image

4. Boot the VM, but press Esc asap and tell the VMWare bios to boot from CD first

5. Reboot the VM into the gparted livecd

6. When it eventually loads, point gparted at the disk device (/dev/sda). Delete the swap partition (/dev/sda5) and then delete the logical partition (/dev/sda2). /dev/sda5 was “inside” /dev/sda2.

The /dev/sda5 swap partition was at the end of the original 5GB drive, but was now sitting in the middle of my 10GB. I couldn’t figure out how to move the swap back so it was just easier to drop it and recreate it after I resized the main /dev/sda1 partition.

7. Resize the 1st partition to almost fill the available space, saving 512MB for a new swap partition

8. Create a new logical partition in the available space, gparted should automatically name this /dev/sda2 when you commit changes.

9. Create a new linux-swap partition inside the /dev/sda2 partition, gparted should automatially name this /dev/sda5 when you commit changes.

10. Reboot the VM, enter the VMWare BIOS and change boot priority so that the VM will boot from it’s disk.

That’s it !

vnc4server on Ubuntu 704 server

Now I have my Gnome desktop running on my sever I’d like to be able to access it without using the vmware console. I installed vnc4server using synaptic. Under my user I type vncserver and then connect to the server using the vnc client from my Windows desktop. By default I get a plain grey X window and a basic xterm window.

To set up a better desktop, edit the file ~/.vnc/xstartup and uncomment the first two lines, as follows:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

#[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &

Thanks to a bug in the vnc4server version that is currently being distributed with 704 “Feisty Fawn”, you need to do two more things

1) sudo chmod +x /etx/X11/xinit/xinitrc

2) edit the vncserver script and add the “-extension XFIXES” line, as follows :

$cmd .= " -rfbauth $vncUserDir/passwd”;
$cmd .= ” -rfbport $vncPort”;
$cmd .= ” -pn”;
$cmd .= ” -extension XFIXES”;

# Add font path and color database stuff here, e.g.:
#

See here and in particular here for more info on this bug.

To Start the vnc server just type:

$ vncserver

Assuming it started a session on :1, you can kill that session with

$ vncserver -kill :1

A GUI for Ubuntu 704 Server ?

I installed Ubuntu Server because I wanted a minimal install befitting a server. No OpenOffice, games or any other stuff. I know my way around a unix command line but it’s just so much quicker to get things done in Windows. Now I think I’d like a light weight GUI on my server that I can start just when I need it. So I need X, Gnome, no login manager and Synaptic for package management.
I’m hoping this should work… Need to look at what’s included in gnome-core.

$ sudo aptitude install xorg gnome-core synaptic

$ startx

Ubuntu 704 Server - Package management with apt and dpkg

To update the local list of packages, enter in a Terminal:

sudo apt-get update

To install all available updates:

sudo apt-get upgrade

To see if package including the words blah is already installed:

dpkg -l '*blah*'

To install a package:

sudo apt-get install package

To remove a package:

sudo apt-get remove package

To list other apt commands and options:

apt-get help

Also try Aptitude for more interactive package management tool
sudo aptitude

Ubuntu 704 Server - Adding a new user

Added myself a new user (should have read the useradd man page first, should be able to set a lot of this all in one command)

  1. useradd
  2. sudo vi /etc/passwd to set group and default shell
  3. sudo vi /etc/group and add new user to the same groups as existing user
    Need to include group admin for sudo
  4. create the home directory /home/…
    chown username folder
    chgrp groupname folder

Ubuntu Server 7.04 (Feisty Fawn)

Installing VMWare image of Ubuntu Server 7.04 “Feisty Fawn” from Chrysaor.info

To reconfigure the console keyboard to GB layout :
$sudo dpkg-reconfigure console-setup

To restart Apache2:
$sudo /etc/init.d/apache2 restart