PostgreSQL startup items for MacOS X

I followed the PostgreSQL installation instructions on Apple's site and got PostgreSQL up and running in no time. To make PostgreSQL start when MacOS starts, I had to do a little more work. I added a startup item as described in James Duncan Davidson's Running Mac OS X Panther. First, I created a startup item directory and used vi to create a parameters file:

root# mkdir -p /Library/StartupItems/PostgreSQL
root# cd /Library/StartupItems/PostgresSQL
root# vi StartupParameters.plist

Next, I guessed that PostgreSQL requires Directory Services and uses Disks and came up with this StartupParameters.plist file:

{
   Description = "PostgreSQL Server";
   Provides = ("PostgreSQL");
   Requires = ("DirectoryServices");
   Uses = ("Disks");
   OrderPreference = "None";
}

Finally, I wrote a startup script to start, restart, and stop PostgreSQL:

#!/bin/sh
. /etc/rc.common
StartService() {
   echo "Starting PostgreSQL"
   sudo -u postgres /usr/local/pgsql/bin/postmaster -i -D /var/postgres/rollerdb &
}
RestartService() {
   echo "Restarting PostgreSQL"
   sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /var/postgres/rollerdb stop
   sudo -u postgres /usr/local/pgsql/bin/postmaster -i -D /var/postgres/rollerdb &
}
StopService() {
   echo "Stopping PostgreSQL"
   sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /var/postgres/rollerdb stop
}
RunService "$1"

Once I was done with that I tested starting, restarting, and stopping PostgreSQL using the SystemStarter command. Once the script worked, I rebooted and found that PostgreSQL did indeed start on startup. It works, but I wonder, is this the best way to configure service for Mac OS X? Davidson's book menioned xinetd and mach bootstrap servers, but says that the SystemStarter is the way to go for now.



Like this post?  del.icio.us Bookmark it   |   submit to dig digg.com Digg it   |   slashdot Slashdot it   |   technorati See who links to it

Comments:

<p>Ack, I should use preview....used to writing in a wiki.. Here we go again</p> <p>I have something similar. My RestartService has some reuse: :-)</p> <pre> RestartService () { StopService StartService } </pre> <p> Also, my startup parameters are a little differnet. I found this somewhere on the net...</p> <pre> { Description = "PostgreSQL database server"; Provides = ("PostgreSQL"); Requires = ("Resolver"); Preference = "Late"; Messages = { start = "Starting PostgreSQL"; stop = "Stopping PostgreSQL"; }; } </pre> <p> This has been working flawlessly for me for several months now. </p><p> To be complete, my startService also uses pg_ctl: </p> <pre> ConsoleMessage "Starting PostgreSQL database server" su - postgres -c '/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l /usr/local/pgsql/logfile -o -i' </pre> <p> And my StopService does a kill in emergency :-)</p> <pre> ConsoleMessage "Stopping PostgreSQL database services" /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data x=`/bin/ps axc | /usr/bin/grep postgres` if /bin/test "$x" then set $x kill -9 $x fi </pre>

Posted by Jon Mountjoy on May 26, 2004 at 03:15 AM EDT #

http://www.entropy.ch:16080/software/macosx/postgresql/ If you scroll down, Marc already made the whole thing into a couple of packages. R

Posted by Robert Sfeir on May 26, 2004 at 07:49 AM EDT #

If you're using the latest postgresql you may also want to create another StartupItem that starts pg_autovacuum.

Posted by arturo on May 26, 2004 at 10:59 AM EDT #

StopService can be called from the command line, but doesn't fire when you choose restart or shutdown from the apple menu. (Haven't tried with 10.3.4, but this is true of 10.3.0) An orielly article about Oracle on OSX pointed this out, which is really a drawback. Has anyone found a workaround?

Posted by Ted on May 26, 2004 at 07:40 PM EDT #

StopService can be called from the command line, but doesn't fire when you choose restart or shutdown from the apple menu. (Haven't tried with 10.3.4, but this is true of 10.3.0) An orielly article about Oracle on OSX pointed this out, which is really a drawback. Has anyone found a workaround?

Posted by Ted on May 27, 2004 at 01:13 PM EDT #

Post a Comment:
  • HTML Syntax: Allowed

This work is licensed under a Creative Commons License.
Copyright 2002-2007, David M Johnson (dave.johnson at rollerweblogger.org)

This is a personal weblog, I do not speak for my employer.