Start background writer during archive recovery. Background writer now performs
[PostgreSQL.git] / contrib / start-scripts / osx / PostgreSQL
blobdc826837a3206a5d8311beec4d78837861512641
1 #!/bin/sh
3 ##
4 # PostgreSQL RDBMS Server
5 ##
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:
14 # /Library/StartupItems/PostgreSQL/PostgreSQL
15 # /Library/StartupItems/PostgreSQL/StartupParameters.plist
17 # Next, add this line to the /etc/hostconfig file:
19 # POSTGRESQL=-YES-
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:
25 # POSTGRESQL=-NO-
27 # For more information on Darwin/Mac OS X startup bundles, see this article:
29 # http://www.opensource.apple.com/projects/documentation/howto/html/SystemStarter_HOWTO.html
31 # Created by David Wheeler, 2002.
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
38 # use the below command in order to correctly start/stop/restart PG with log rotation script:
39 # SystemStarter [start|stop|restart] PostgreSQL
41 ################################################################################
42 ## EDIT FROM HERE
43 ################################################################################
45 # Installation prefix
46 prefix="/usr/local/pgsql"
48 # Data directory
49 PGDATA="/usr/local/pgsql/data"
51 # Who to run the postmaster as, usually "postgres". (NOT "root")
52 PGUSER="postgres"
54 # the logfile path and name (NEEDS to be writeable by PGUSER)
55 PGLOG="${PGDATA}/logs/logfile"
57 # do you want to rotate the log files, 1=true 0=false
58 ROTATELOGS=1
60 # logfile rotate in seconds
61 ROTATESEC="604800"
64 ################################################################################
65 ## STOP EDITING HERE
66 ################################################################################
68 # The path that is to be used for the script
69 PATH="$prefix/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
71 # What to use to start up the postmaster (we do NOT use pg_ctl for this,
72 # as it adds no value and can cause the postmaster to misrecognize a stale
73 # lock file)
74 DAEMON="$prefix/bin/postmaster"
76 # What to use to shut down the postmaster
77 PGCTL="$prefix/bin/pg_ctl"
79 # The apache log rotation utility
80 LOGUTIL="/usr/sbin/rotatelogs"
82 . /etc/rc.common
84 StartService () {
85 if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
86 ConsoleMessage "Starting PostgreSQL database server"
87 if [ "${ROTATELOGS}" = "1" ]; then
88 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 | ${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
89 else
90 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
95 StopService () {
96 ConsoleMessage "Stopping PostgreSQL database server"
97 sudo -u $PGUSER $PGCTL stop -D "$PGDATA" -s -m fast
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
107 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 | ${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
108 else
109 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
111 else
112 StopService
116 RunService "$1"