Using NTPD in a Ubuntu 8.04 Xen Virtual Machine

It's a good idea to have an accurate clock on any computer you access - apart from anything else it means your logs will be consistent making event replays easier. Unfortunately over time each computer will slowly drift away from the actual time. NTP - network time protocol - keeps the clock accurate by synchronising it with a group of computers elsewhere on the internet. Unfortunately, Xen guests such as those provided by Xeriom Networks tend to be tied to the clock of the Xen host. This is a quick walk-through to show how to setup NTP and remove the dependence on the physical host.

Taking a shortcut

If you're running a Ubuntu based VM and you use the package host at Xeriom Networks then you can run this simple command to setup NTP.

sudo apt-get install xeriom-ntp-client --yes --force-yes

Gaining Independence

To stop your VM's clock being slaved to the hosts simply tell the kernel that the clock is independent.

sudo su -c "echo 1 > /proc/sys/xen/independent_wallclock"

To make sure that this persists over reboots, edit /etc/sysctl.conf to include xen.independent_wallclock = 1.

Installing and configuring NTPD

An NTP daemon can be installed using apt-get.

sudo apt-get install ntp --yes

If you're on one of Xeriom's VMs you can use time.xeriom.net as a timesource. Edit /etc/ntp.conf to use it, and perhaps a few other servers from the nearest NTP pool to you.

server time.xeriom.net prefer
server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org
server 2.uk.pool.ntp.org

Restart NTP and you're done.

sudo /etc/init.d/ntp restart

What's the time Mr. Wolf?

NTP will take maybe 15 minutes to settle down and select the best possible configured timesource to synchronise with. You can check how it's doing by using ntpq -p.

ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.xeriom.net 212.13.194.87    3 u   39   64  377    0.402  -45.729   7.496
+dns1.rmplc.co.u 195.66.241.3     2 u   39   64  377    3.443  -54.808   6.142
+ntpt1.core.thep 194.152.64.68    3 u   40   64  377    0.723  -53.765   5.965
+weevil.pwns.ms  249.240.53.144   2 u   38   64  377    9.110  -57.739  11.427

This output contains quite a bit of information - for more complete details check out http://www.novell.com/coolsolutions/trench/418.html.

Now there's no excuse for being late

If you found this article useful, give me some love over at Working With Rails.

State of Ruby / Xen API's

Recently I've been doing a lot of work on creating a management interface for Xen VMs in one of my Rails applications. The current state of Xen API's is not well documented which makes it rather hard to implement. In fact, just about the only comparison that I can find of the API's appears to be on the Xen mailing list in an email from Ewan Mellor.

  • xend-http-server: Very old and totally broken HTML interface and legacy, generally working SXP-based interface, on port 8000.
  • xend-unix-server: Ditto, using a unix domain socket.
  • xend-unix-xmlrpc-server: Legacy XML-RPC server, over HTTP/unix, the recommended way to access Xend in 3.0.4.
  • xend-tcp-xmlrpc-server: Ditto, over TCP, on port 8006.
  • xen-api-server: All new, all shiny Xen-API interface, available in preview form now, and landing for 3.0.5.
-- Ewan Mellor, 2007-01-24 in http://lists.xensource.com/archives/html/xen-api/2007-01/msg00006.html

As far as I can tell, if you use Xen <= 3.0.4 the best option is to use the Ruby-Xen gem to work with the legacy Xen XML-RPC API. If you're using Xen >= 3.0.5 the preferred method of integration appears to be the almost-undocumented Xen API*, which as far as I can tell has no existing Ruby client.

A paper which talks about the Xen API is available at http://research.iu.hio.no/theses/pdf/master2007/ingard.pdf which seems to suggest that the new Xen API also uses XML-RPC, with a sample script available at http://folk.uio.no/ingardm/thesis/xensource.xeninfo.pl.

In the following weeks I hope to setup some modern Xen dom0's and begin to document exactly what is required to get the Xen API setup and accessible from a host within the same network as the dom0.

* Update, 2008-03-15

I found a draft definition of the new XML-RPC API on the XenSource Wiki. A huge cake is the prize for anyone that writes a BSD or MIT licenced Ruby interface against the specification given there.

About the boy

A picture of Craig in grayscale

Craig Webster is a software engineer living in London. He usually works with Ruby although sometimes he sneaks in some Erlang or JavaScript. He's into rock climbing, snowboarding, skating, photography and fencing. Yes, this does mean he has a sword.

Near here you'll find Craig's homepage, contact details, PGP key and keysigning policy, and talks.

Licence

The entire content of this blog is public domain. Use it however you fancy. You don't even need to attribute it to me, although it would be nice if you did. Just don't sue me and we'll all be happy.

I Work With Rails

Recommend Me

My Travels

I go places. Do you go places too? Let's meet up!.