Welcome to the adventure

A subversion init.d script for Ubuntu Linux

Saturday September 30, 2006

There are hundreds of guides out there to get svn running in tandem with Apache. However, if, like me, you want to use the svnserve program so subversion isn’t tied to Apache services, then this is for you.

Here’s a cheat sheet/script for creating a new subversion repo:

sudo apt-get install subversion
svnadmin create /svn/newRepo
groupadd subversion
chown -R root:subversion /svn/newRepo
chmod -R ug+rw /svn/newRepo

The above repo is now available to any users in the subversion group (add them via /etc/group). You can check out the repo using

svn co svn+ssh://myserver.com/svn/newRepo

(assuming your user has ssh access to the box and is in the group “subversion”).

If you want anonymous access, you need to run svnserve. Unfortunately no init.d script is distributed with it on Ubuntu (or anywhere else I know of), so it’s non-trivial to run it as a daemon. You can hook it into xinetd, but I can never get xinetd working.

So here’s a regular init.d script I wrote (the latest version has lots of contributions from commenters). Nothing fancy; it just runs the command svnserve -d, and then runs it through the kill command to shut it down.

You can run it as user subversion (create with “adduser subversion”) or you can just run it as root. Just change the SVN_USER and SVN_GROUP variables (thanks Andrew!)

(Download it here)

#!/bin/sh -e
#
# svnserve - brings up the svn server so anonymous users
# can access svn
#

# Get LSB functions
. /lib/lsb/init-functions
. /etc/default/rcS

SVNSERVE=/usr/bin/svnserve
SVN_USER=subversion
SVN_GROUP=subversion
SVN_REPO_PATH=/home/$SVN_USER/

# Check that the package is still installed
[ -x $SVNSERVE ] || exit 0;

case "$1" in
	start)
		log_begin_msg "Starting svnserve..."
		umask 002
		if start-stop-daemon --start 
		--chuid $SVN_USER:$SVN_GROUP 
		--exec $SVNSERVE 
		-- -d -r $SVN_REPO_PATH; then
			log_end_msg 0
		else
			log_end_msg $?
		fi
	;;

	stop)
		log_begin_msg "Stopping svnserve..."
		if start-stop-daemon --stop --exec $SVNSERVE; then
		log_end_msg 0
		else
		log_end_msg $?
		fi
	;;

	restart|force-reload)
		"$0" stop && "$0" start
	;;

	*)
	echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
		exit 1
	;;
esac

exit 0

Save it as /etc/init.d/svnserve, and start it with

/etc/init.d/svnserve start

Add it to start every time you boot:
update-rc.d svnserve defaults

Death to the crickets

Friday September 29, 2006

It has become apparent to me that the most pressing problem to focus our resources on is the destruction of the cricket. This baneful insect has plagued mankind for billions of years (…) with its maleficent chirping, bent on an evil purpose — to crawl and reproduce incessantly in the dwellings of humans, slowly driving them insane and to eventual distinction. At that time crickets will assume dominion over the earth in our stead.

fldcricket_female.jpg

I’m thinking nano robots that can crawl under carpets, plant bombs on the backs of the crickets, and detonate them when the crickets enter the proximity of others, utilizing a 20 foot blast radius.

I propose funneling US $90 billion of research funding into this area until the problem is at least under control; otherwise, we will soon suffer annihilation at the hands of this insidious insect.

Why satellite Internet blows

Monday September 25, 2006

Reply from 64.233.167.99: bytes=32 time=608ms TTL=236
Reply from 64.233.167.99: bytes=32 time=702ms TTL=236
Reply from 64.233.167.99: bytes=32 time=627ms TTL=236
Reply from 64.233.167.99: bytes=32 time=733ms TTL=236
Reply from 64.233.167.99: bytes=32 time=831ms TTL=236
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 64.233.167.99: bytes=32 time=4447ms TTL=236
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 64.233.167.99: bytes=32 time=623ms TTL=236
Reply from 64.233.167.99: bytes=32 time=594ms TTL=236
Reply from 64.233.167.99: bytes=32 time=601ms TTL=236
Reply from 64.233.167.99: bytes=32 time=601ms TTL=236

Keeping a ping up on another monitor is the only way to keep from pulling your hair out when a website stops responding to you.

Running multi-threaded Apache with PHP on Ubuntu

Friday September 22, 2006

If you try to install apache2-mpm-worker or apache2-mpm-perchild on Ubuntu, it will not let you do so alongside apache2-mod-php5.

The story is that many modules php might potentially load are not thread safe, and so running it in a threaded Apache is “not recommended”. However, with threaded Apache2, you get better performance and you might be able to wing running your PHP app without any problems. Mix these two at your own risk.

PHP has to have experimental multi-threading compiled in to run with multithreaded Apache, which is why you can’t just install the apache-worker and mod-php packages together. You’ll have to build it yourself, but this guide will show you how to compile php from source in Ubuntu.

# apt-get install apache2-mpm-worker

(or apt-get install apache2-mpm-perchild, the other multi-threaded Apache implementation).

I needed these to get Apache running on my production server, so you may need them too:

apt-get install build-essential flex libxml2-dev

If you want to compile PHP with a MySQL driver, you’ll need these development bits:

apt-get install libmysqlclient14-dev

Download the latest PHP sources (I’m using 5.1.6). Direct link to the latest version at the time of writing:

wget http://us3.php.net/get/php-5.1.6.tar.bz2/from/this/mirror
tar -xvjf php-5.1.6.tar.bz2
cd php-5.1.6

You must compile PHP with the location of your apache2 binary. I’m compiling in mysql support. You must also use the “–enable-maintainer-zts” switch to compile in threading support, or you will get “Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. Pre-configuration failed!” when you try and load mod-php into Apache.

./configure --with-apxs2=/usr/bin/apxs2 --with-mysql --enable-maintainer-zts --prefix=/usr
make
sudo make install

You can then set the php module to load, and restart Apache

a2enmod php5
/etc/init.d/apache2 restart

And that should be it. I already had a working PHP/Apache setup on my system before I did this (although PHP was removed automatically when I installed apache2-mpm-worker), so I might be missing a step that you need from a fresh Ubuntu install (let me know and I’ll add it).

No hint of instability. apache2-mpm-worker is running this very blog (Wordpress) as I write.

fact hunter - dynamic chuck norris & jack bauer facts

Monday September 18, 2006

I’ve been writing this site to help me learn asp.net. It’s software that collects funny facts about popular characters (e.g. Chuck Norris). Thing that’s a bit different is it’s highly user driven. Very easy to get a new account (takes literally 5 seconds) and throw up some new facts. You can view the newest facts, top facts of the week and top facts of all time. There’s digg-style fact rating to help the better facts bubble to the top, and you can comment on specific facts.

If you’re a techie/math guy and have never seen Bruce Schneier facts, check them out.
“Bruce Schneier uses a 512 bit number for his ATM pin.”
“Bruce Schneier once factored a prime number.”

The site uses a fair amount of Ajax, made possible with Anthem.NET. I was using Microsoft’s own upcoming Ajax toolkit, Atlas, but it is pre-release, and so it’s buggy and feature-incomplete. I also couldn’t get it running on Mono’s beta asp.net support and so I dropped it in favor of the open source Anthem.NET. Although, I even had to make some small patches to Mono to get Anthem.NET running too (shame it doesn’t work out of the box - maybe it will in Mono 1.1.18).

Even though I developed this app in Visual Studio, I wanted to be able to run it on Mono because Linux web servers are much easier to administrate, and I like working in Linux. I did have this site running on a Windows VPS (VPSLand) for awhile, using their cheapest Windows plan (which is still $25 a month!) and the site was dog slow. Random out of memory exceptions would crop up while browsing the site, and if I had remote desktop open into the machine, it would run out of RAM and I wouldn’t be able to compile the site in place.

Now that the site runs on Mono, I can put it on my very fast Linux VPS (Xen-based Server Axis). I could have just upgraded my VPSLand account, but comparable specs to my Server Axis account would cost 2-3x as much.

Moving multiple files in subversion

Sunday September 17, 2006

Ever tried moving many files with svn? You can conveniently do this:

svn remove *.cs

but vexingly you cannot do this:

svn move *.cs newFolder/

So memorize this oft-used iteration idiom (bash):


for i in *.cs ; do svn mv $i newFolder/ ; done

Which will move all *.cs files (or whatever shell-expansion expression you use) to newFolder/

Gmail enhancements, shortcut keys

Thursday September 14, 2006

If you’re not using Gmail shortcut keys, you should, since their hotkey support is great. Enable it in Settings.

Anyway, Gmail vexingly doesn’t have a “delete mail” shortcut key, even though it has got to be one of the most used email functions.

However, if you’re using Firefox (or Camino), you can repair this by adding delete key functionality to Gmail along with other enhancements using custom user scripts via GreaseMonkey, a Firefox extension. Install it for Firefox or Epiphany.

Try Mihai Parparita’s infinitely useful Gmail Macros script, which adds a delete button and a beautiful and usable labeling UI [Post | direct link to script]

There’s also conversation preview bubbles [direct link to script], which are cool, athough I haven’t found myself using them often.

Chase

Tuesday September 12, 2006
a vampiric moon commands the night
and speeds the crawl of inimical chase.
   stay close, move toward the river's light;
and from the drawing net escape.

six pence we place in the boatman's hand
and twice again for his silence made.
   I swore I'd bring you to safe lands;
for isles we sail in muted wake.

we search to conceal from alarm at day-
tangled brush we slip into.
   here we're hid and long we'll stay;
and past thick boughs watch skies peer through.

Including javascript in Internet Explorer with the <script> tag

Saturday September 9, 2006

Awesome IE bug #57057127986198731 : if you include javascript via the <script> tag, make sure you do it like this:

<script src="script.js" type="text/javascript"></script>

and not like this:

<script src="script.js" type="text/javascript" />

although the latter case works in Firefox, and should be valid, IE (5 & 6) will choke on it, stop processing javascript (which started messing up my conditional IE-only style sheets) and will give you the very descriptive JavaScript error:

line 1
char 1
error: object expected
code: 0

The “solution” to this bug is a bit hard to track down on Google, so here it is.