How to start/stop database from rake?


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

$ cat run-rake
#! /bin/sh


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,
I can say “rake foobar” instead of “run-rake foobar”

Any hints?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs