How to start/stop database from rake?

Hello,

I would like to start the database server (postgres) before tests are run
and stop it afterwards. For this, I have created a little wrapper around
rake:

   $ cat run-rake
   #! /bin/sh
   
   DB=`pwd`/db/pgdata
   
   # init database cluster if it does not exist yet
   [ -d $DB ] || initdb -D$DB
   
   # start the database server
   pg_ctl -D$DB -o "-h '' -k $DB" -l postgreslog start
  
   # wait for it to accept connections
   sleep 1
   
   # run rake with original arguments
   rake "$*"
   
   # we're done, stop database server again
   pg_ctl -D$DB -o "-h '' -k $DB" -l postgreslog stop

But this doesn't "feel" like RoR, So I'd like to integrate it into rake, so
I can say "rake foobar" instead of "run-rake foobar"

Any hints?