David Reynolds

Welcome to boredom

Django Fcgi Init Script

| Comments

I’ve just added another Django site to my VDS using FCGI and was looking for an init script to start and stop them when I stumbled across this. I had to do a bit of fiddling to get it working with Debian (I think there was possibly a different version of start-stop-daemon, or something).

This is what I came up with and it seems to be working pretty well for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /bin/sh
### BEGIN INIT INFO
# Provides:          FastCGI servers for Django
# Required-Start:    networking
# Required-Stop:     networking
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Start FastCGI servers with Django.
# Description:       Django, in order to operate with FastCGI, must be started
#                    in a very specific way with manage.py. This must be done
#                    for each DJango web server that has to run.
### END INIT INFO
#
# Author:  Guillermo Fernandez Castellanos
#          <guillermo.fernandez.castellanos AT gmail.com>.
#
# Version: @(#)fastcgi 0.1 11-Jan-2007 guillermo.fernandez.castellanos AT gmail.com
#
# Altered by David Reynolds for Debian Stable <david AT reynoldsfamily.org.uk>

#### SERVER SPECIFIC CONFIGURATION
export PYTHONPATH=/var/www/django/trunk/:/var/www/django/
DJANGO_SITES="mysite stmarys"
SITES_PATH=/var/www/django
RUNFILES_PATH=$SITES_PATH/run
HOST=127.0.0.1
PORT_START=3033
RUN_AS=www-data
#### DO NOT CHANGE ANYTHING AFTER THIS LINE!

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="FastCGI servers"
NAME=$0
SCRIPTNAME=/etc/init.d/$NAME

#
#       Function that starts the daemon/service.
#
d_start()
{
    # Starting all Django FastCGI processes
    PORT=$PORT_START
    for SITE in $DJANGO_SITES
    do
        echo -n ", $SITE"
        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
            echo -n " already running"
        else
            start-stop-daemon --start \
            --exec /usr/bin/python $SITES_PATH/$SITE/manage.py runfcgi method=threaded \
            host=$HOST port=$PORT pidfile=$RUNFILES_PATH/$SITE.pid --pidfile $RUNFILES_PATH/$SITE.pid
            chmod 400 $RUNFILES_PATH/$SITE.pid
        fi
        let "PORT = $PORT + 1"
    done
}

#
#       Function that stops the daemon/service.
#
d_stop() {
    # Killing all Django FastCGI processes running
    for SITE in $DJANGO_SITES
    do
        echo -n ", $SITE"
        start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
                          || echo -n " not running"
        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
           rm $RUNFILES_PATH/$SITE.pid
        fi
    done
}

ACTION="$1"
case "$ACTION" in
    start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;

    stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;

    restart|force-reload)
        echo -n "Restarting $DESC: $NAME"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;

    *)
        echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

exit 0

Thanks Guillermo!

Watching a Film on NTL On:demand

| Comments

As Carl was visiting last night we decided to watch a film and I thought it might be interesting to try out the ‘new’ NTL on:demand thingy. It seems like a very good idea but in practise, it took me three attempts (where attempt is trying to find a film and having to reboot the set top box) to get the film playing. Once the film was finally running, it worked pretty well. The controls were quite slow to respond, but it did what it should.

The film we picked to watch was Confetti which has various stars from Peep Show and Spaced in it. I wasn’t expecting much from the film but it actually turned out to be pretty good. It is the story of 3 couples who are taking part in a competition to win a house. The competition involves coming up with the wackiest wedding. There is a tennis wedding, a 40s musical wedding and a Naturist wedding. From what I’ve read much of the movie was improvised, which made it feel to me slightly more ‘real’ feel than a normal film to me (that and it being not filmed on film).

There is an obvious winner to the competition, but after seeing the three weddings, I was left thinking that anyone could have won.

All in all, a pretty good film and worth a watch, in my opinion.

Uninstalling or Removing a .pkg File

| Comments

It took me a bit of digging around to find this, so I thought I’d record it here in the hope that it might help someone in the future.

If you’ve just installed something on your OS X system (I’ve done this on Tiger, can’t vouch for it working on anything other than that) and you want to remove it, what can you do? The installer with the package doesn’t have an uninstaller and you can’t find a list of files anywhere to remove, so what can you do? Well, this:

$ lsbom package.pkg/Contents/Archive.bom

This will return you a list of files which you can then go through and remove, I’ve yet to come up with a script to do it as the list of files contains top level folders as well as files and I couldn’t work out a quick way to differentiate between them.

Standard New Site Post

| Comments

So yeh, new site can’t be arsed to write about it in depthly, just trying to draw attention to it. Any comments/thoughts on the design welcome (but not too scathing, thanks).

Back to normal new site post….

Random ramblings about the technology used, problems had with it, cool things I did, cool things about the site, how easy it was, how hard it was, etc, etc, etc…

Delcious Library Barcode Scanning

| Comments

I finally got around to picking up the webcam that Adam offered to lend me and trying it out with Delicious Library and I thought I’d record my experiences.

I hooked up the webcam and having no software to test it with, I resorted to using Yahoo Messenger to see if the camera was working. It was, but it was terribly focused, so I twiddled the focusing ring, but that made it worse. As I continued to twist it, the ring jammed and I finally resorted to taking the camera apart, focusing it and then putting it back together again.

Once the camera was all up and running, I opened Delicious Library and opened the barcode scanning window. I found that the best way of scanning the barcode was to get it in focus above the red lines, then drag it through the lines. I also found, for some reason, that scanning the barcodes upside down seemed to work better. Once I got into it, I managed to enter about 220 items (with about 10% scanning failure) in about 2 hours, which was a hell of a lot quicker than entering the barcode numbers by hand.

Click here to see a screenshot of Delicious Library in action.

Edit: I forgot to mention the “Easter Eggs” in Delicious Library… Each title you scan has it’s title spoken by the default voice on your Mac. When you ‘bleep’ a Harry Potter film, after announcing the title, the system says “VOLDEMORT” in a scary voice. Similarly, if you can a Star Wars film it says “I am your father” in the same voice. I wonder if there are any more famous quotes in there…..

Fetching Your Hotmail Into Normal Mailbox

| Comments

I’ve always wondered if there was a solution to this and since I keep getting emails that I miss because they go into my hotmail account, I thought I’d see if there was anything out there to do the job.

The thing I found was a perl script called gotmail which you can run on the command line (or cron) and it will fetch your Hotmail email and dump it into your mailbox.

I currently have this set up to fetch any new email in my hotmail mailbox, shove it through my local spamassassin and stick it in my Inbox - which seems to be doing what I want.

Reminder to Myself

| Comments

Installing grub onto a new disk from an old disk… do the following:

1
2
3
4
5
6
# grub
grub>
grub> device (hd0) /dev/sda
grub> root (hd0,1)
grub> setup (hd0)
grub> quit

Replace device with correct device and dada! it works…