source: projects/specs/trunk/p/postgresql/postgresql.init @ 7299

Revision 7299, 7.0 KB checked in by iwaim, 11 years ago (diff)

postgresql 9.0.7-2vl7

  • Property svn:executable set to *
Line 
1#! /bin/sh
2# postgresql    This is the init script for starting up the PostgreSQL
3#               server
4#
5# chkconfig: - 85 15
6# description: Starts and stops the PostgreSQL backend daemon that handles \
7#              all database requests.
8# processname: postmaster
9# pidfile: /var/run/postmaster.pid
10
11# Version 6.5.3-2 Lamar Owen
12# Added code to determine if PGDATA exists, whether it is current version
13#     or not, and initdb if no PGDATA (initdb will not overwrite a database).
14
15# Version 7.0 Lamar Owen
16# Added logging code
17# Changed PGDATA.
18#
19
20# Version 7.0.2 Trond Eivind Glomsrd <teg@redhat.com>
21# use functions, add conditional restart
22         
23# Version 7.0.3 Lamar Owen <lamar@postgresql.org>
24# Check for the existence of functions before blindly using them
25# in particular -- check for success () and failure () before using.
26# More Cross-distribution support -- PGVERSION variable, and docdir checks.
27
28# Version 7.1 Release Candidate Lamar Owen <lamar@postgresql.org>
29# initdb parameters have changed.
30
31# Version 7.1.2 Trond Eivind Glomsrd <teg@redhat.com>
32# Specify shell for su
33# Handle stop better - kill unwanted output, make it wait until the database is ready
34# Handle locales slightly differently - always using "C" isn't a valid option
35# Kill output from database initialization
36# Mark messages for translation
37
38# Version 7.1.2-2.PGDG Lamar Owen <lamar.owen@wgcr.org>
39# sync up.
40# Karl's fixes for some quoting issues.
41
42# Version 7.2b2 Lamar Owen <lamar.owen@wgcr.org>
43# version change.
44
45# Version 7.2 final.  Lamar Owen <lamar.owen@wgcr.org>
46# reload from Peter E.
47# Eliminate the pidof postmaster test in stop -- we're using pg_ctl so we don't need pidof.
48# Tested the $? return for the stop script -- it does in fact propagate.
49# TODO: multiple postmasters.
50
51# VErsion 7.3 Lamar OWen <lamar.owen@ramifordistat.net>
52# Multiple postmasters, courtesy Karl DeBisschop
53
54# Version 7.4 HOTTA Michihide <hotta@net-newbie.com>
55# Version 8.0 HOTTA Michihide <hotta@net-newbie.com>
56# Version 8.1 HOTTA Michihide <hotta@net-newbie.com>
57# Version 8.2 Shu KONNO <owa@bg.wakwak.com>
58
59# Version 9.0 IWAI, Masaharu <iwaim.sub@gmail.com>
60# fix su(1) paramaters in start() and stop().
61
62# PGVERSION must be replaced real version
63# In vine new postgresql.spec, version must be replaced by building
64PGVERSION=9.0
65
66# Source function library.
67INITD=/etc/rc.d/init.d
68. $INITD/functions
69
70# Get function listing for cross-distribution logic.
71TYPESET=`typeset -f|grep "declare"`
72
73# Get config.
74. /etc/sysconfig/network
75
76# Find the name of the script
77NAME=`basename $0`
78
79# Set defaults for port and database directory
80PGPORT=5432
81export PGDATA=/var/lib/pgsql
82if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base/template1 ]
83then
84        echo "Using old-style directory structure"
85else
86        export PGDATA=/var/lib/pgsql/data
87fi
88
89# Override defaults from /etc/sysconfig/pgsql if file is present
90[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
91export PGDATA
92export PGPORT
93export PGOPTS
94
95# Check that networking is up.
96# Pretty much need it for postmaster.
97[ "${NETWORKING}" = "no" ] && exit 0
98
99[ -f /usr/bin/postmaster ] || exit 0
100
101start(){
102        PSQL_START=$"Starting ${NAME} service: "
103
104        # Check for the PGDATA structure
105        if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
106        then
107        # Check version of existing PGDATA
108
109                if [ `cat $PGDATA/PG_VERSION` != $PGVERSION ]
110                then
111                        SYSDOCDIR="(Your System's documentation directory)"
112                        if [ -d /usr/doc/postgresql-$PGVERSION ]
113                        then
114                                SYSDOCDIR=/usr/doc
115                        fi
116                        if [ -d /usr/share/doc/postgresql-$PGVERSION ]
117                        then
118                                SYSDOCDIR=/usr/share/doc
119                        fi
120                        if [ -d /usr/doc/packages/postgresql-$PGVERSION ]
121                        then
122                                SYSDOCDIR=/usr/doc/packages
123                        fi
124                        if [ -d /usr/share/doc/packages/postgresql-$PGVERSION ]
125                        then
126                                SYSDOCDIR=/usr/share/doc/packages
127                        fi
128                        echo
129                        echo $"An old version of the database format was found.\nYou need to upgrade the data format before using PostgreSQL.\nSee $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
130                        exit 1
131#                       This doesn't seem to do anything useful...
132#               else
133#                       if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
134#                       then
135#                               success "$PSQL_CHECK"
136#                       else
137#                               echo "  [ OK ]"
138#                       fi
139#                       echo
140                fi
141
142        # No existing PGDATA! Initdb it.
143
144        else
145                echo -n $"Initializing database: "
146                if [ ! -d $PGDATA ]
147                then
148                        mkdir -p $PGDATA
149                        chown postgres.postgres $PGDATA
150                        chmod go-rwx $PGDATA
151                fi
152                # Make sure the locale from the initdb is preserved for later startups...
153                [ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
154                # Just in case no locale was set, use en_US
155                [ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
156                # Is expanded this early to be used in the command su runs
157                echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
158                # Initialize the database
159                # su -l postgres -s /bin/sh -c "/usr/bin/initdb --pgdata=$PGDATA -E EUC_JP --no-locale > /dev/null 2>&1" < /dev/null
160                # now no need to specify the locale with no-locale option
161                su -l postgres -s /bin/sh -c "/usr/bin/initdb --pgdata=$PGDATA > /dev/null 2>&1" < /dev/null
162                [ -f $PGDATA/PG_VERSION ] && echo_success
163                [ ! -f $PGDATA/PG_VERSION ] && echo_failure
164                echo
165        fi
166
167        # Check for postmaster already running...
168        # note that pg_ctl only looks at the data structures in PGDATA
169        # you really do need the pidof()
170        pid=`pidof -s /usr/bin/postmaster`
171        if [ $pid ] && /usr/bin/pg_ctl status -D $PGDATA > /dev/null 2>&1
172        then
173                echo $"Postmaster already running."
174        else
175                #all systems go -- remove any stale lock files
176                rm -f /tmp/.s.PGSQL.${PGPORT} > /dev/null
177                echo -n "$PSQL_START"
178                su -l -s /bin/sh -c "/usr/bin/pg_ctl  -D $PGDATA -p /usr/bin/postmaster -o '-p ${PGPORT}' start  > /dev/null 2>&1" postgres < /dev/null
179                sleep 1
180                pid=`pidof -s /usr/bin/postmaster`
181                if [ $pid ]
182                then
183                        if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
184                        then
185                                success "$PSQL_START"
186                        else
187                                echo_success
188                        fi
189                        touch /var/lock/subsys/${NAME}
190                        echo $pid > /var/run/postmaster.pid
191                        echo
192                else
193                        if echo "$TYPESET"|grep "declare -f failure ()" >/dev/null
194                        then
195                                failure "$PSQL_START"
196                        else
197                                echo_failure
198                        fi
199                        echo
200                fi
201        fi
202}
203
204stop(){
205        echo -n $"Stopping ${NAME} service: "
206        su -l -s /bin/sh -c "/usr/bin/pg_ctl stop -D $PGDATA -s -m fast" postgres > /dev/null 2>&1
207        ret=$?
208        if [ $ret -eq 0 ]
209        then
210                echo_success
211        else
212                echo_failure
213        fi
214        echo
215        rm -f /var/run/postmaster.pid
216        rm -f /var/lock/subsys/${NAME}
217}
218
219restart(){
220    stop
221    start
222}
223
224condrestart(){
225    [ -e /var/lock/subsys/${NAME} ] && restart
226}
227
228reload(){
229    su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl reload -D $PGDATA -s" > /dev/null 2>&1
230}
231
232# This script is slightly unusual in that the name of the daemon (postmaster)
233# is not the same as the name of the subsystem (postgresql)
234
235# See how we were called.
236case "$1" in
237  start)
238        start
239        ;;
240  stop)
241        stop
242        ;;
243  status)
244        status postmaster
245        ;;
246  restart)
247        restart
248        ;;
249  condrestart)
250        condrestart
251        ;;
252  reload|force-reload)
253        reload
254        ;;
255  *)
256        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
257        exit 1
258esac
259
260exit 0
261
Note: See TracBrowser for help on using the repository browser.