« JSP as XML | Main | Hatteras »

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.

Comments:

Ack, I should use preview....used to writing in a wiki.. Here we go again

I have something similar. My RestartService has some reuse: :-)

RestartService ()
{
    StopService
    StartService
}

Also, my startup parameters are a little differnet. I found this somewhere on the net...

{
  Description   = "PostgreSQL database server";
  Provides      = ("PostgreSQL");
  Requires      = ("Resolver");
  Preference    = "Late";
  Messages =
  {
    start = "Starting PostgreSQL";
    stop  = "Stopping PostgreSQL";
  };
}

This has been working flawlessly for me for several months now.

To be complete, my startService also uses pg_ctl:

    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'

And my StopService does a kill in emergency :-)

	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

Posted by Jon Mountjoy on May 26, 2004 at 06: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 10: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 01:59 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 26, 2004 at 10: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 04:13 PM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« JSP as XML | Main | Hatteras »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Mac, some may be related to this entry.