My ongoing experiences with Ubuntu, and later Mythbuntu, as a media center with MythTV. I'm also using the system for a virtual machine server, a mediawiki server and a general all around home infrastructure base.

Monday, June 29, 2009

Getting Django running under Apache

I heard a number of good things about Django and wanted to give it a try. After following the tutorial and playing around with it, I found it really cool. BTW, there is also good documentation to be found at the Django Book site.

After playing a little, I decided I wanted to try deploying Django into my existing Apache instance. And well, I found the documentation for doing this somewhat lacking (even in the book). But I forged ahead and catched what it took here. Hopefully it will either be helpful or someone can come along and tell me I missed something.

First, I started by installing Django on my Ubuntu server. I already had Apache installed and working btw.
sudo apt-get install python-django

Reading through the Django document I decided to go the modwsgi route since that seem to be the recommended course. I followed the directions for installing modwsgi:
sudo apt-get install libapache2-mod-wsgi

Then I created a Django site to run my applications in. Pick the name of your site carefully - as far as I can tell, it will appear in all your URLs (maybe I'm wrong on this as I haven't experimented too much):
cd /usr/local
sudo django-admin startproject django_site

Now, you could just go ahead and make your site owned by the Apache user (www-data), but I decided to make it owned by me so that I could easily edit things:
sudo chown -R vwelch django_site
Now create /usr/local/django_site/django.wgsi that looks like the following:
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_site.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Now go ahead and edit /usr/local/django_site/ and set up your database. I used SQLite3 since it was the simplest. You will need to put the database somewhere the Apache user (www-data) has write access. In my case I created a directory just for this purpose:
sudo mkdir /usr/local/django_db
sudo chown www-date /usr/local/django_db

So the relevant two lines of my file looked like:
DATABASE_NAME = '/usr/local/django_db/database.db'

Now go ahead and create the database - you must do this as the Apache user:
sudo -u www-data ./ syncdb

Time to proceed with Apache configuration. Create the file /etc/apache2/sites-available/django.conf (using 'sudo vi') so that it looks like the following. Note that I believe the first argument to WSGIScriptAlias "/django_site" must patch your site name. The second line lets the admin application find it's CSS (I haven't dealt with the case another application also wants CSS).
WSGIScriptAlias /django_site /usr/local/django_site/django.wsgi
Alias /media /var/lib/python-support/python2.6/django/contrib/admin/media

Now enable the site in Apache and restart it:
sudo a2ensite django.conf
sudo apache2ctl restart

Now visit you should be able to visit http://hostname/django_site and get a Django welcome page. If not, well, something is wrong :-/

At this point you can add applications under /usr/local/django_site as you normally would and have them appear at http://hostname/django_site/appname

Good luck. And as I mentioned I figured this out through mostly trial and error. If anyone can correct me or point me at better docs, I'd be grateful.

Sunday, June 14, 2009

Uninstalling VMWare 2.0.1, installing VMWare 1.0.9 on Ubuntu 9.0.4

I had previously installed VMWare 2.0.1 and I hate it. I'm probably going to move to VirtualBox, but I need VMWare for a while until I transition, so I decided to take another run at getting VMWare 1.0.9 to install.

First, to uninstall VMWare 2.0.1:
# /usr/bin/
Then I downloaded VMWare 1.0.9 from the VMWare website.

Previously I had run into this bug which caused the vmmon build to fail.

The trick to getting it to build is to use this patch following the directions from this tutorial, which worked for me despite it being for an older version.

USB thumb drive mounting writable only by root...

I had a thumb drive that was mounting on my Ubuntu laptop OK, but was writable only by root.

Long story short, I figured out it was something about the way it was formatted. When I tried to put the same thumb drive into my Mac, it wouldn't mount it and I had to reformat it. After that it mounted just fine on my Ubuntu laptop and was owned by when when I did so.

Not sure how I formatted it in the first place, but lesson learned is that certain formats mount OK but will not be user writable.

Monday, June 8, 2009

Installing Virtualbox and creating Ubuntu VMs on headless Ubuntu 9.04 server

Here's my situation: Ubuntu 9.04 server, headless and I want to install Virtualbox on it and get Ubuntu 8.04 LTS servers running as root.

Step 1: Install Virtualbox

Following the directions at the Virtualbox Linux download page I did the following:

1a) Edited /etc/apt/sources.list and add the virtual box repository:
deb jaunty non-free

1b) Add the virtualbox key to the apt keyring:
wget -q -O- | sudo apt-key add -

1c) And install:
apt-get install virtualbox-2.2

Step2: Configured bridged networking

I basically followed the directions on the wiki.:

2a) Install bridge-utils:

apt-get install bridge-utils

2b) Now edit /etc/network/interfaces and add the br0 interface with the same address as your primary interface (eth0 in my case). Note that these directions assume you are using a static IP, if not you are on your own. My /etc/network/interfaces now looks like this:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static

# Configured per
# Address of br0 should be the same as eth0
auto br0
iface br0 inet static
bridge_ports eth0 vbox0 vbox1

2c) Now restart the networking:

/etc/init.d/networking restart

...wait a couple minutes for the network to come back - my SSH session survived the restart YMMV...

Now I have a br0 interface:

# ifconfig br0
br0 Link encap:Ethernet HWaddr 00:18:8b:76:32:11
inet addr: Bcast: Mask:
inet6 addr: fe80::218:8bff:fe76:3211/64 Scope:Link
RX packets:87 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6130 (6.1 KB) TX bytes:11447 (11.4 KB)

2d) Create /etc/vbox/interfaces:
vi /etc/vbox/interfaces

So that it looks like:
vbox root br0

2e) Restart virtualbox networking, but hmmm, I don't have /etc/init.d/vboxnet, but I do have /etc/init.d/vboxdrv so I restarted that instead:
/etc/init.d/vboxdrv restart

2f) I skipped setting permissions on /dev/net/tun since I'm running VMs as root.

Step 3: Create a VM

I basically followed these directions, updated as I went. Also kudos to Sasquatch for the nic1 and bridgeadapter1 options.

3a) Create the new VM. You should be able to set the memory as you see fit. Other options you probably don't want to mess with.

VBoxManage -q createvm -name Ubuntu-Server -register
VBoxManage -q modifyvm Ubuntu-Server -memory 384MB -acpi on -ostype ubuntu -pae on -nic1 bridged -bridgeadapter1 br0

Note that if you have other VMs using vrdp you probably want to add "-vrdpport #" to use an available port (default port is 3389).

3b) Create disk for the new VM and attach it. I created an 8GB disk based on my experiences trying to use smaller disks.
VBoxManage -q createhd -filename "Ubuntu-Server.dvi" -size 8192 -register
VBoxManage -q modifyvm Ubuntu-Server -hda Ubuntu-Server.dvi

3c) Download the iso for 8.04 server from Ubuntu. Note I use 8.04 since it has long-term support and hence I won't have to worry about upgraded the OS on the VM as often. Note that while the Ubuntu page tried to get me to use the 64 bit version, I found it did not work for me (I got the following error trying to boot with it: "This kernel requires an x86-64 CPU, but only detected an i686 CPU. Unable to boot - please use a kernel appropriate for your CPU.") so I used the 32 bit version instead. You should also choose a copy from a local mirror.


3d) Register the iso image and attach it to the VM:
VBoxManage -q registerimage dvd /path/to/ubuntu-8.04.2-server-i386.iso
VBoxManage -q modifyvm Ubuntu-Server -dvd /path/to/ubuntu-8.04.2-server-i386.iso

Ok, we now have a VM that's ready to boot and install Ubuntu...

Step 4: Start the VM and Connect to it via vrdp

4a) Start the VM in vrdp mode:
VBoxManage -q startvm Ubuntu-Server --type vrdp

4b) Connect using a remote desktop client. What I found worked for me from my Ubuntu 9.04 laptop was 'rdesktop' from the commandline:
rdesktop server-name

Or from my Mac, Remote Desktop Connection, though it does give a warning about "Remote Desktop Connection cannot verify the identity of the computer that you want to connect to."

Step 5: Do a standard Ubuntu Install
Ok, you should now be looking at the console on the VM which has booted from the CD. Go ahead and do your standard Ubuntu install.

When the install completed, I found the system automatically rebooted from the hard drive without me having to do anything to unmount iso image.

Step 6: Clean up

The only thing to do is detact the iso from the VM. After powering off the VM, do the following:
VBoxManage -q modifyvm Ubuntu-Server -dvd none

Saturday, June 6, 2009

sftp subsystem dying

I tried to open a nautilus bookmark of a sftp session to my server today and it closed immediate with a "Could not open location 'sftp://vwelch@host' ssh program unexpectedly exited' message.

Running a sshd in debug mode on the server and I saw the following:
subsystem request for sftp
debug1: subsystem: exec() /usr/lib/openssh/sftp-server
debug1: Received SIGCHLD.
So for some reason my sftp-server subsyst is immediately failing. No idea why. Will update here when I figure it out.

Making a SSH connection to a NAT'ed Virtualbox VM

I found myself wanting to SSH to a NAT'ed virtualbox VM. I discovered this post which nicely described how to use VBoxManage to accomplish this. The only change I had to make on my Ubuntu box was to use 'pcnet' instead of 'e1000'.