Annotation of pgsql/contrib/start-scripts/osx/PostgreSQL, revision 1.4

1.1       momjian     1: #!/bin/sh
                      2: 
                      3: ##
                      4: # PostgreSQL RDBMS Server
                      5: ##
                      6: 
                      7: # PostgreSQL boot time startup script for Darwin/Mac OS X. To install, change
                      8: # the "prefix", "PGDATA", "PGUSER", and "PGLOG" variables below as
                      9: # necessary. Next, create a new directory, "/Library/StartupItems/PostgreSQL".
                     10: # Then copy this script and the accompanying "StartupParameters.plist" file
                     11: # into that directory. The name of this script file *must* be the same as the
                     12: # directory it is in. So you'll end up with these two files:
                     13: #
                     14: #    /Library/StartupItems/PostgreSQL/PostgreSQL
                     15: #    /Library/StartupItems/PostgreSQL/StartupParameters.plist
                     16: #
                     17: # Next, add this line to the /etc/hostconfig file:
                     18: #
                     19: # POSTGRESQL=-YES-
                     20: #
                     21: # The startup bundle will now be ready to go. To prevent this script from
                     22: # starting PostgreSQL at system startup, simply change that line in
                     23: # /etc/hostconfig back to:
                     24: #
                     25: # POSTGRESQL=-NO-
                     26: #
                     27: # For more information on Darwin/Mac OS X startup bundles, see this article:
                     28: #
                     29: #  http://www.opensource.apple.com/projects/documentation/howto/html/SystemStarter_HOWTO.html
                     30: #
                     31: # Created by David Wheeler, 2002.
                     32: 
                     33: # modified by Ray Aspeitia 12-03-2003 : 
                     34: # added log rotation script to db startup
                     35: # modified StartupParameters.plist "Provides" parameter to make it easier to 
                     36: # start and stop with the SystemStarter utitlity
                     37: 
                     38: # use the below command in order to correctly start/stop/restart PG with log rotation script:
                     39: # SystemStarter [start|stop|restart] PostgreSQL
                     40: 
                     41: ################################################################################
                     42: ## EDIT FROM HERE
                     43: ################################################################################
                     44: 
                     45: # Installation prefix
                     46: prefix="/usr/local/pgsql"
                     47: 
                     48: # Data directory
                     49: PGDATA="/usr/local/pgsql/data"
                     50: 
                     51: # Who to run the postmaster as, usually "postgres".  (NOT "root")
                     52: PGUSER="postgres"
                     53: 
                     54: # the logfile path and name (NEEDS to be writeable by PGUSER)
                     55: PGLOG="${PGDATA}/logs/logfile"
                     56: 
                     57: # do you want to rotate the log files, 1=true 0=false
                     58: ROTATELOGS=1
                     59: 
                     60: # logfile rotate in seconds
                     61: ROTATESEC="604800"
                     62: 
                     63: 
                     64: ################################################################################
                     65: ## STOP EDITING HERE
                     66: ################################################################################
                     67: 
                     68: # The path that is to be used for the script
1.3       tgl        69: PATH="$prefix/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
1.1       momjian    70: 
1.4     ! tgl        71: # What to use to start up the postmaster.  (If you want the script to wait
        !            72: # until the server has started, you could use "pg_ctl start -w" here.
        !            73: # But without -w, pg_ctl adds no value.)
1.1       momjian    74: DAEMON="$prefix/bin/postmaster"
                     75: 
                     76: # What to use to shut down the postmaster
                     77: PGCTL="$prefix/bin/pg_ctl"
                     78: 
                     79: # The apache log rotation utility
                     80: LOGUTIL="/usr/sbin/rotatelogs"
                     81: 
                     82: . /etc/rc.common
                     83: 
                     84: StartService () {
                     85:     if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
                     86:         ConsoleMessage "Starting PostgreSQL database server"
                     87:         if [ "${ROTATELOGS}" = "1" ]; then
1.4     ! tgl        88:             sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} '${PGLOG}' ${ROTATESEC} &
1.1       momjian    89:         else
                     90:             sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
                     91:         fi
                     92:     fi
                     93: }
                     94: 
                     95: StopService () {
                     96:     ConsoleMessage "Stopping PostgreSQL database server"
                     97:     sudo -u $PGUSER $PGCTL stop -D "$PGDATA" -s -m fast
                     98: }
                     99: 
                    100: RestartService () {
                    101:     if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
                    102:         ConsoleMessage "Restarting PostgreSQL database server"
                    103:        # should match StopService:
                    104:        sudo -u $PGUSER $PGCTL stop -D "$PGDATA" -s -m fast
                    105:        # should match StartService:
                    106:         if [ "${ROTATELOGS}" = "1" ]; then
1.4     ! tgl       107:             sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} '${PGLOG}' ${ROTATESEC} &
1.1       momjian   108:         else
                    109:             sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
                    110:         fi
                    111:     else
                    112:         StopService
                    113:     fi
                    114: }
                    115: 
                    116: RunService "$1"

PostgreSQL CVSweb <[email protected]>