Monthly Archives: June 2007

Ubuntu Server 7.04 Fiesty: Mounting or Accessing a USB Drive in Bash Shell

I ran into a problem today accessing a USB Drive in Ubuntu Server. In Windows and in Ubuntu Standard, plug and play works fine. My laptop, which has Ubuntu installed, immediately recognized the USB drive once it was plugged in. I accessed its contents in the Bash shell by typing:

ls -l /media
ls -l /media/ExternalHDD

Typing the same thing in Ubuntu Server will not yield the same results. Ubuntu 7.04 server does not come with automatic mounting. After plugging in your drive, you need to run a few commands before access to the drive will be allowed. The first command is to install a program called ‘pmount’. Type:

sudo apt-get install pmount

After installing the pmount, you need to figure out what the drive is called on your system. Type:

fdisk -l

You should see output that looks like this:

Disk /dev/sdf: 300.0 GB, 300069052416 bytes
255 heads, 63 sectors/track, 36481 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdf4 * 1 36481 293033601 7 HPFS/NTFS

The USB drive I am using is called ‘/dev/sdf4’. To mount the drive, you’re need to create a directory to alias the drive and use pmount to reference the alias. To do this I type:

sudo mkdir /media/usbdrive
pmount /dev/sdf4 /media/usbdrive

Afterwards, I copied a bunch of files on the USB drive and set the ownership of the files from root to myself. I typed:

sudo cp -R /media/usbdrive/filesToCopy /home/alex/
cd /home/alex
sudo chown -R alex:alex filesToCopy

New Article

CruiseControl Server and Django: How to Setup CruiseControl to Automatically Deploy Django Applications

In a previous article, I described how to deploy the Django based application to a server running Ubuntu Server 7.04 and Apache 2.0 running mod_python. This article intends to expand upon that configuration by adding automated deployment using CruiseControl and Subversion source control server. CruiseControl is a java based server that has the ability to monitor a variety of source control servers, such as Subversion,  for changes and execute scripts or programs for deploying and configuring an application whenever changes are detected in source control.

Installing CruiseControl requires downloading the Java 6 runtime files, downloading the CruiseControl application, and configuring which source control paths to monitor and their associated actions. My CruiseControl configuration consists of two separate ‘projects’ – one for monitoring static files and another for monitoring the Django application itself.

First install the Java 6 runtime and JDK files. You can do this by typing:

sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk

Before downloading the CruiseControl application, I created a separate user account , called ‘deploy’, for monitoring and executing deployments. This created a separate home directory for the user and alleviated any worries about permissions  or ownership that may affect directory or file access.

You can create a new user called ‘deploy’ and add it to the administrative group by typing the following:

sudo adduser deploy
sudo adduser deploy admin

After creating the new user account, log into the new account and download CruiseControl. Type:


Unzip CruiseControl by typing


Since this is a java application, the only thing required for installation is a directory for the java files to live in. In my configuration, I renamed the CruiseControl directory from ‘cruisecontrol-bin-2.7’ to ‘cc’. Type:

mv cruisecontrol-bin-2.7 cc

My path for CruiseControl now looks like this: ‘/home/deploy/cc’

If you haven’t yet, you need to add the JAVA_HOME path variable to your account. You can do this by editing the ‘.profile’ file in the current user’s home directory. I did this by typing:

vi ~/.profile

After opening the file, scroll to the very end of the file and append the following text:


export JAVA_HOME

This will add the JAVA_HOME path variable. The variable should be set to the location of the java-6 jre subdirectory. In order for these changes to take place, you need to re-login into your account.

After logging into your account again, go to the directory where you extracted CruiseControl and run the CruiseControl shell script. I did this by typing:


This initiates CruiseControl for the first time and allows the server to test itself against an example project that comes with the default installation. If you see a few errors related to accessing an Subversion repository, don’t worry about it.

After the confirming that the server works, stop the server by killing the process. I did this by finding the pid in the ‘/home/deploy/cc/’ file. Type:

sudo kill PID_NUMBER

In the following text, we’re going to configure CruiseControl to deploy a Django application. First, let’s remove the example project (which is called ‘connectfour’) and replace it with a Django deployment project and a project for deploying static files. In the previous article, I created two separate deployment locations – one called ‘assets’, which stores static files, and another called ‘ALEXKUO’, which is the Django Application.

The CruiseControl project names will be ‘assets’ and ‘webapp’. In your CruiseControl directory [‘/home/deploy/cc’], type:

cd projects
rm -rf connectfour
mkdir assets
mkdir webapp

The projects directory will contain the Python scripts used to delete and re-checkout files from Subversion. We also need to setup the logs directory. In your CruiseControl directory [‘/home/deploy/cc’], type:

cd logs
rm -rf connectfour
mkdir assets
mkdir webapp

Next we need to edit the CruiseControl configuration file or ‘/home/deploy/cc/config.xml’. To open type:

vi config.xml

My configuration file looks like the following:

<project name="webapp">


<currentbuildstatusbootstrapper file="logs/webapp/buildstatus.txt"/>


<modificationset quietperiod="10">

<svn RepositoryLocation="" />


<schedule interval="30">

<exec workingdir="/home/deploy/cc/projects/webapp"


args="" />



<currentbuildstatuslistener file="logs/webapp/buildstatus.txt"/>



<currentbuildstatuspublisher file="logs/webapp/buildstatus.txt"/>



<project name="assets">


<currentbuildstatusbootstrapper file="logs/assets/buildstatus.txt"/>


<modificationset quietperiod="10">

<svn RepositoryLocation="" />


<schedule interval="30">

<exec workingdir="/home/deploy/cc/projects/assets"


args="" />



<currentbuildstatuslistener file="logs/assets/buildstatus.txt"/>



<currentbuildstatuspublisher file="logs/assets/buildstatus.txt"/>



As you can see from my config.xml file, the project tag defines a unique project. Each project monitors a specific repository location for changes. These repository locations are defined by the ‘modificationset’ and ‘svn’ tags. Whenever changes are detected, the schedule and exec tags are activated. The publishers, listeners, and bootstrappers files are log files that record activity during monitoring, building, and deployment.

The ‘’ files contains a python script for deleting a target directory and re-checking out files from a target SVN location. Let’s create these files.

For the webapp project, create a file call ‘’ in the ‘/home/deploy/cc/projects/webapp’ directory. I did this by typing:

touch /home/deploy/cc/projects/webapp/

Next, let’s edit this file. In the ‘/home/deploy/cc/projects/webapp’, type:


My for the webapp looks like this:

from os import system, fchdir, getcwd
from shutil import copy, rmtree

import os

DJANGO_APP_DIR = '/home/deploy/django/django_projects/ALEXKUO'


APP_SETTINGS = '/home/deploy/django/appsettings/ALEXKUO/'



IS_APP_UP = False

"Remove all files in App directory and check out files"
if os.path.exists(DJANGO_APP_DIR):
IS_APP_UP = True


The script first removes all files in the targeted Django application directory, this is done with the command ‘rmtree(DJANGO_APP_DIR)’.  I also copy a ‘’ modified for the server because the Django configuration between my local development box and public server is different. The SVN checkout is initiated with the command ‘system(cout_app)’.

Next let’s create the deploy script for the asset files. In the ‘/home/deploy/cc/projects/assets’ directory, type:


Now let’s edit this file by typing:


My for the assets project looks like this:

from os import system, fchdir, getcwd
from shutil import copy, rmtree

import os

ASSET_DIR = '/home/deploy/websites/'

SVN_ASSET = 'Assets '



"""Delete Asset directory and re checkout asset folder """
if os.path.exists(ASSET_DIR):


This python script is identical to the deploy script for the webapp, except that it excludes commands for copying the ‘’ file.

After creating your python deployment scripts, your build server should be ready for use. Turn on the server by going to the cruise control directory (/home/deploy/cc) and typing:


You can now log off the account and your server will still be running. You can access the server’s status page by opening your browser and typing in the URL: ‘http://<server’s IP address>:8080/”


Ubuntu Server 7.04 Fiesty: Installation Problems and Changing Network Settings from DHCP to Static IP

Tonight I deployed another installation of Ubuntu Server 7.04 Fiesty. The biggest problem I ran into was setting up the network card. Apparently, the Ubuntu setup wizard tries to contact the network in at least two points during the installation wizard. In one of the points of the installation, failure to contact a server on the internet results in the installation hanging. I got around this by running the installation while connected to my residential DHCP network and then redeploying the server to the DMZ, which requires defining a static IP.

This created another problem – How do you change the network settings from DHCP to static IP address? In order to solve this problem, you need to update your interfaces file to use an assigned static IP address and configure the server to use your network’s DNS servers.

To change your network settings from DHCP to static IP, type:

sudo vi /etc/network/interfaces

The file displayed should have a line that says ‘ iface eth0 inet dhcp’ or something similar. Change the file to look like the following:

auto eth0
iface eth0 inet static

Afterwards, restart your network interface by typing:

sudo /etc/init.d/networking restart

Next, you need to configure your DNS servers. You need at least two entries. To edit your DNS entries type:

sudo vi /etc/resolv.conf

My file looked like this:


After saving the file, you should be able to connect to the network.

If you would like to edit your hosts file, type the following in your shell.

sudo vi /etc/hosts

You can add more references to your localhost in here. Mine looks like this:       localhost alex-server sandbox-server

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

If you would like to change the hostname of your server, type the following:

sudo vi /etc/hostname

After typing in your new hostname, you need to run a script to implement the change. Type:

sudo /etc/init.d/ start


Removing Graffiti on my Car

The other day somebody in the neighborhood dribbled touch up paint all over my car. Judging from a bottle of paint that was left near the crime scene, I think it’s lacquer-based. After pondering what to do, I consulted Google and ran into this post. It explained that I should use something called Goof-Off for removing the offending paint. This stuff really does work, however, it takes quite a bit of elbow grease to get the paint off.

At first I used Q-tips to remove the splotches of paint, but I found that it was easier to just use a soft paper towel. It took about 2.5 hours to remove all the dribbles and spots. The only word of caution I can offer to anyone out there when using ‘Goof-off’ is to take it easy on the pin stripes. This stuff is powerful enough to take the stripes off (which is bad), but not powerful enough to get through the clear coat (which is good).

After 2.5 hours of rubbing and cleaning, the paint was taken off without any problems.

Killing processes and PostgreSQL Queries

I’ve been working on issues related to processes and PostgreSQL these past few days. Minor as they were, I think these are common issues that aren’t documented very well. I recently had a problem canceling queries issued from PGAdmin. I decided to cancel the queries by looking up the process id and canceling the process thats running the query.

You can look up the process id, or the ‘pid’ column, by executing the following query in psql or PGAdmin:

select * from pg_stat_activity;

This query will return a list of all processes currently being run by your server. After finding the query you want to cancel, go to the BASH prompt and type:

sudo kill pid_number

Another problem that I ran into the other day was figuring out which processes a java server was running on. I did this by querying processes by name or browsing through all of the server’s processes. To query processes by a name, I typed:

ps -o user,pid,ppid,command -ax | grep java

If you still can’t find the process, you can browse all processes by typing:


New Article

PostgreSQL: Backup and Restoring a Database

Backups are performed by a utility called ‘pg_dump’  while  ‘psql’ can be used to restore from a backup file. Normally, people use the utility ‘pg_restore’, however, this utility requires the user to backup the database using a custom or tarball  format. If you use plain text, which is the default format when using ‘pg_dump’, then you must use ‘psql’ to restore the database. The current database I’m working with is still quite small, weighing in at about 645 megabytes.

To backup the database I typed:

pg_dump -v  -O --port=5432 --username=alex database_name > database_name.sql

The ‘-v’ flag turns on verbose mode and the -O flag skips any attempt to set a owner to the database. Other options that I tested were the -C flag for adding a create database statement and the ‘-c’ flag for adding drop table statements. I omitted the ‘-C’ and the ‘-c’ flags because I decided to restore into an existing database. Without the specification of file sizes and format, pg_dump will create one plain text file for the backup.

Some file systems have limitations on the maximum file size. NTFS file sizes are limited by the Max volume size of the drive – which is two terabytes, while FAT32 is limited to about four gigabytes. The EXT2 file system has a max file size of two terabytes. Max file sizes for Ext3 and Ext4 vary depending on block sizes, between 16 gigabytes to 2 terabytes. If needed, you can split files by piping into the split utility. The split utility is found only on Linux, Unix, and Cygwin.

To do this type:

pg_dump database_name | split -bytes=100m backup.bak.

This splits the plain text format of the backup into 100 megabyte pieces with the file named as ‘backup.bak.XXX’ where XXX is a digit.

If needed, you can append the backed up files when restoring by typing:

cat backup.bak. | psql -d database_name

If you’re restoring from a single plain text file, type:

psql -d database_name -f database_name.sql

If the database exists, errors will be thrown and the restore will fail – unless you specified the ‘-c’ flag in ‘pg_dump’ to add the ‘drop tables’ statements.

If you used the plain text format for your backup, creating an archive from the backup file can reduce the file size. For myself, zipping the backup file reduced the size from 695 megabytes to 60 megabytes.

For more information on file systems or backing up databases, please consult these links:

Milestone: First Django Application Ever

I finally deployed a Django application to a public facing Linux server. You can read all about it in a write up below. For those of you who don’t know what I’m talking about, Django is another ‘rapid application development’ web framework that comes with all sorts of useful tools to help web application developers get their software finished faster. Some of these time saving features include an auto generated administration tool, an ORM object mapper, and a template engine.

So how does developing on Django compare with development on ASP.NET? Well, for non-MS Office related development I would say it is faster and more suitable for custom applications. Alot of this has to do with the object relational mapper, which accomplishes the same things as Microsoft’s Dlinq, and the generated admin tool. These two features alone completely remove a large amount of coding that usually has to be done when creating an ASP.NET application.

I highly recommend anyone out there give Django a try. Check out this tutorial for a quick introduction.

New Article

Python: How to Setup a Django Application on Apache 2.0 with mod_python on Ubuntu Server 7.04 Fiesty

For web developers who don’t have much system administration experience, deploying applications to production is the last hurdle that just doesn’t happen smoothly either because of a lack of experience or because of a lack of planning beforehand. The following is a how to guide based on my first experience of deploying a Django application to an environment running the following:

  • Ubuntu Server 7.04 Fiesty
  • Apache 2
  • mod_python
  • Django Framework
  • The Python database adapter or API that your application uses. In my case, it was ‘psycopg’.
  • The Database your application uses. I’m using PostgreSQL 8.2 for this deployment

Other things you will need in order to a install Django application include:

  • Subversion 1.2+
  • FTP Client
  • Administrative access (‘sudo’).
  • An application using Django Framework
  • Access to the virtual host files in the /etc/apache2/sites-available’
  • A website setup using Apache 2.0

I assume the user already has Ubuntu, Apache 2, and a database installed on the target host. If you haven’t already installed mod_python for Apache 2 and Subversion, you can do so by SSH’ing or logging into your server and type the following:

sudo apt-get install libapache2-mod-python subversion

Next we need to setup the directories that will be holding our Django project files and the Django framework. I usually place these files in a subdirectory in the user’s home directory. For my last deployment, I made a root directory called DJango with two subdirectories: django_src (stores framework) and django_projects (stores your django applications). I did this by typing:

mkdir /home/alex/django
mkdir /home/alex/django/django_src
mkdir /home/alex/django/django_projects

We should now download the Django framework. We can get the latest copy using Subversion. I did this by typing:

sudo svn co /home/alex/django/django_src

Next, we need to add the Django framework to the Python interpreter. I did this by adding a symbolic link to Python’s site-packages directory. In this environment, I am using Python 2.5. Type:

sudo ln -s /home/alex/django/django_src/django /usr/lib/python2.5/site-packages/django

In the next following paragraphs, I’m going to go into detail on how I organized and setup my Django application files on the server. When developing a Django application, there are two separate types of files being deploy: static files that are not processed by the Apache mod_python module, such as CSS, Django templates, javascript, and images, and Python files that need to be processed by the Apache mod_python module (.py files).

I prefixed all references to static files with ‘/assets/’. This is going to be the root directory in our website that will hold all static files. On a side note, your source control directories should have separate directories for holding Django python files and static files used by your Django application.

In the target website folder on the host, I created a subdirectory called ‘/assets/’. I did this by typing:

sudo mkdir /home/alex/websites/

Copy your static files into the assets directory.

Django applications commonly use the admin tool. In my projects, I specify the path to the static admin tool files by adding a symbolic link called ‘/admin_media/’. You can do this by typing:

sudo ln -s /home/alex/django/django_src/django/contrib/admin/media /home/alex/websites/

Next we are going to copy your Django application files to the server. To do this, create a Django folder named after your application. It is important that you name the directory the same as your application name. As a result, the name of the directory will be case sensitive. To find out your application’s name, open the ‘’ file and look for the variable ‘ROOT_URLCONF’. The application name can be found by looking at its value. For example, ‘APPLICATION_NAME.urls’.

I created the folder by typing:

mkdir /home/alex/django/django_projects/your_django_project_application_name

Before copying your application files over, I recommend editing the so that it will work properly with your host environment. The variables that need to be set that are specific to deployments are :

  • Database variables

 The following is a portion of my file:


DATABASE_ENGINE = 'postgresql'

DATABASE_NAME = 'alexkuoinfo'


MEDIA_ROOT = '/home/alex/websites/'


ADMIN_MEDIA_PREFIX = '/admin_media/'





Copy your django application files to ‘/home/user/django/django_projects/your_django_application_name’.

Now we need to setup Apache to process requests using mod_python. This requires the user to edit the virtual host file for the site. On my server, I am using a unique virtual host file for each site. These files are located in the ‘/etc/apache2/sites-available/’ directory. If you would like more information on adding virtual hosts to your Apache installation, consult this tutorial.

Edit the your virtual hosts file for the site, to do this I typed:

cd /etc/apache2/sites-available
sudo vi

After editing my virtual host file, it looked like this:

<VirtualHost *> 

DocumentRoot /home/alex/websites/

<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath "['/home/webdeploy/django/django_projects'] + ['/home/webdeploy/django/django_projects/ALEXKUO'] + sys.path"
<Location "/admin_media/">
SetHandler None
<Location "/assets/">
SetHandler None
ErrorLog /var/log/apache2/

After saving your changes to the virtual host file, you should restart Apache. Type:

sudo a2ensite
sudo /etc/init.d/apache2 restart

The settings in the virtual host file unique to a Django application are the Location elements. The element ‘<Location “/”>….</Location> ‘ tells Apache that all requests received from the root directory and subdirectories should use mod_python to interpret the request. The environment variable, ‘DJANGO_SETTINGS_MODULE’ specifies the settings module used for Django’s PythonHandler. The PythonPath references your Django application’s directory. You have to specify the root and subdirectory paths for your Django application or else import commands will fail when your application is compiled and run.

The next two Location elements specify that files in “/admin_media/” and “/assets/” directories should not be handled by mod_python.

If you’re working with a development machine and would like to see changes in your application files immediately, it is convenient to force Apache2 to reload your Django application per request. To do this, add the following in your ‘/etc/apache2/httpd.conf’ file and restart the Apache webserver.

MaxRequestsPerChild 1

Another alternative to reloading your Django application is to change the ‘’ file for your application. This is useful if you have other websites or applications running on your server. I usually just change the DEBUG variable from False to True.

That’s it. Since this is my first deployment, I’m open to any comments, suggestions, questions, or critiques.

For more information about deploying Django applications, please consult the following links:

The Garage Door is Broken

In any engineering project, finding the cause of a problem can be just as hard as fixing the actual problem. Today our garage door broke, so my roommates and I tried to fix it. At first we thought the problem was caused by a broken axle on one of the track wheels. After inspecting the plate, we quickly found out that the axle was just fine.

Axle wheel

Then we decided to inspect one of the guide wire wheels. The guide wires were definitely incorrectly configured. We found that the wire had not re-wrapped itself properly, causing the motor to push harder on the garage door when closing.

Guide wire wheel

This still didn’t explain why the door wouldn’t close though. Stepping back to look at the garage door, we quickly realized that the two sides were not falling down at the same rate, causing one side to close faster than the other – warping one of the guide rails.

Uneven door

After examining the brackets that secure the track wheels to the door, we found one of the brackets had cracked. This created a harder ‘push’ on one side than the other when closing.

Cracked plate

The end result is this:

Outside Garage

Inside Garage

At this point, we decided to call the repairman.

New Articles

Review: Shreveport, LA – Eldorado Casino and Horseshoe Bossier City (Shreveport), LA

I decided to take a day trip to Shreveport, LA with some friends – partly because I haven’t been to Shreveport and partly because I was curious what my friends meant by ‘gambling on the cheap’. Ever since I visited Las Vegas, seeing the two words ‘gambling’ and ‘cheap’ was kind of like seeing ‘girls’ and ‘LAN party’ used in the same sentence. Before I go on, I think its important that readers know this review is done by a person who is not into gambling and hates the thought of loosing money. Although I have no qualms about gambling, I think there are better ways to spend your money.

After a 3.5 hour drive from Dallas on I-20, we arrived at the casino Horseshoe. One of the odd rules about Louisiana and gambling is that gambling cannot take place on land. In response, casinos are built on ‘riverboats’. The riverboats can be seen all along the Red River and look like barges permanently attached to hotels. At the Horseshoe, the gambling facility has three floors with slot machines on all floors along with black jack tables, craps, and a poker room. First we checked out the craps table and shortly after we decided to look at the poker room. With a minimum buy-in of $100, the poker room hosted 1,22 dollar no limit and 5,10 dollar no limit tables with seating capacity of 10 per table. All games being played were Texas Hold’em. After observing a couple of hands at the 1,2, I noted that a person needs to bring a minimum of $400 in order to play. Even though the tables are 1,2 dollar, there is no limit to the amount a person can bet at a time – which negates the whole point of a ‘1,2’ dollar poker table. It wasn’t uncommon to see players raising $50 to $100 on the river or turn.

The next casino we visited was the Eldorado. In comparison with the Horseshoe, I found the Eldorado much nicer. The ceilings were higher in the casino, which made it less smokey, and the gambling area looked bigger than the Horseshoe. Overall, the place looked a little more modern and cleaner. Upon entering the casino, we decided to check out the poker room again. However, I found out that all tables were playing ‘Omaha’ style poker, which I am not familiar with. Next, we all visited the black jack tables. I believe these are the cheapest black jack tables I have ever visited. When I was in Vegas, the cheapest black jack table I could find was a $25 minimum. All the tables here were $5 minimum with a max of $1000.  The shoes at the black jack table housed about 7 or 8 decks and each shoe was reshuffled at the table after about 8 hands. Drinks were served by waitresses about once per shoe. Overall, I found the black jack tables to be fairly well run. After a short stint at the black jack tables, we hit the craps tables for a few hours. I don’t know how to play craps, so I just watched.

Overall, I think a visit to Shreveport is worth a day trip if you need to get a fix, but it just doesn’t compare to Las Vegas. I saw a variety of people in the casinos. Most of the clientele at the Horseshoe and the Eldorado looked like either regulars or members of the AARP. I saw the most visitors at the Eldorado, probably because its one of the nicer casinos in the area. As for buffet prices, lunch averaged about $12 while dinner is about $20.

The following is a summary of the ups and downs for the day.

Player Gain/Loss Games Played
Me (Alex) +$15  Blackjack
Bob Even  Blackjack, Craps, Video Poker, Slots
Joe -$120  Blackjack, Craps, Slots, Craps
Dave -$640  Poker, Craps