Archive for the ‘Code’ Category

FreeBSD 7.0: installing psycopg 2.07

Wednesday, July 23rd, 2008

While setting up a new FreeBSD 7.0 server I found that psycopg 2.0.7 doesn't easy_install on FreeBSD. It's because of a configuration problem in config.h at the bottom.

#if defined(__FreeBSD__) || (defined(_WIN32) && !defined(__GNUC__)) || defined(__sun__)
/* what's this, we have no round function either? */
static double round(double num)
{
  return (num >= 0) ? floor(num + 0.5) : ceil(num - 0.5);
}
#endif
 

However 'round' is defined in FreeBSD and has been since FreeBSD 5.3 (according to the manual page). The fix is simple, just remove the 'defined(__FreeBSD__) ||' part of the '#if' and you should be fine. Now you can 'easy_install .' psycopg2.

PS: I'd tried to raise a ticket but http://www.initd.org/ trac seems to have been down for ages.

Mac OSX: starting postgres on boot

Thursday, July 3rd, 2008

Every bloody operating system has it's own unique way of starting things at boot time. Today I bothered to learn how OS X does it. Here's how I got PostgreSQL to start when my machine is turned on:

What gets started is handled by a program called SystemStarter. On boot it looks through /Library/StartupItems for folders. Inside those folders it looks for a script with the same name as the folder and a plist called StartupParameters.plist.

So as super user:

cd /Library/StartupItems/
mkdir PostgreSQL
touch PostgreSQL/PostgreSQL
touch PostgreSQL/StartupParameters.plist
 

Now we need to fill in the details. In PostgreSQL/PostgreSQL enter:

#!/bin/sh
 
sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile start

This is a long line, but it's basically running postgres (via pg_ctl) as the user postgres. You'll need to change this to the whatever user you run postgres as and where ever your install of postgres is. I've used the standard names and directories so it's likely this will work for you too.

Now lets look at the plist. This file contains information for SystemStarter about when to start postgres, what postgres needs and provides and any messages to print to log files:

 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
        <key>Description</key>
        <string>PostgreSQL</string>
        <key>Messages</key>
        <dict>
                <key>start</key>
                <string>Starting PostgreSQL</string>
                <key>stop</key>
                <string>Stopping PostgreSQL</string>
        </dict>
        <key>OrderPreference</key>
        <string>None</string>
        <key>Provides</key>
        <array>
                <string>PostgreSQL</string>
        </array>
</dict>
</plist>
 

You can test your new settings by typing sudo SystemStarter -n -D, fix any error messages, reboot and you should have postgres all the time :)

More command line meme data

Friday, April 11th, 2008

Since everyone else is doing this... I thought I would join in

dazza@macpro:~>history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' |sort -rn|head
96	svn
85	python
44	nosetests
40	./start-tgmetalinfo.py
37	ssh
28	tgenv
20	mate
16	cd
14	curl
13	ls
 

that's a bit weird. I do a lot of svn as I merge from development to release. I'm surprised (and pleased) to see nosetests (unit test suite) being called so frequently. tgenv is an alias I have for setting up my workingenv for TurboGears (I have many different version of turbogears installed). mate is the command line call to TextMate (text editor) from the current directory. I think the curls are there from debugging calls to AWS (Amazon Web Services).