123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
-
- PGVERSION=@pgver@
- INITD=/etc/rc.d/init.d
- . $INITD/functions
- TYPESET=`typeset -f|grep "declare"`
- . /etc/sysconfig/network
- NAME=postgresql
- PGPORT=5432
- export PGDATA=/var/lib/pgsql
- if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base/template1 ]
- then
- echo "Using old-style directory structure"
- else
- export PGDATA=/var/lib/pgsql/data
- fi
- [ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
- export PGDATA
- export PGPORT
- export PGOPTS
- [ "${NETWORKING}" = "no" ] && exit 0
- [ -f /usr/bin/postmaster ] || exit 0
- start(){
- PSQL_START=$"Starting ${NAME} service: "
- # Check for the PGDATA structure
- if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
- then
- # Check version of existing PGDATA
- if [ `cat $PGDATA/PG_VERSION` != $PGVERSION ]
- then
- echo
- echo $"An old version of the database format was found.\nYou need to upgrade the data format before using PostgreSQL.\nSee @docdir@/README.rpm-dist for more information."
- exit 1
- # This doesn't seem to do anything useful...
- # else
- # if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
- # then
- # success "$PSQL_CHECK"
- # else
- # echo " [ OK ]"
- # fi
- # echo
- fi
- # No existing PGDATA! Initdb it.
- else
- echo -n $"Initializing database: "
- if [ ! -d $PGDATA ]
- then
- mkdir -p $PGDATA
- chown postgres.postgres $PGDATA
- chmod go-rwx $PGDATA
- fi
- # Make sure the locale from the initdb is preserved for later startups...
- [ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
- # Just in case no locale was set, use en_US
- [ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
- # Is expanded this early to be used in the command su runs
- echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
- # Initialize the database
- # su -l postgres -s /bin/sh -c "/usr/bin/initdb --pgdata=$PGDATA -E EUC_JP --no-locale > /dev/null 2>&1" < /dev/null
- # now no need to specify the locale with no-locale option
- su -l postgres -s /bin/sh -c "/usr/bin/initdb --pgdata=$PGDATA > /dev/null 2>&1" < /dev/null
- [ -f $PGDATA/PG_VERSION ] && echo_success
- [ ! -f $PGDATA/PG_VERSION ] && echo_failure
- echo
- fi
- # Check for postmaster already running...
- # note that pg_ctl only looks at the data structures in PGDATA
- # you really do need the pidof()
- pid=`pidof -s /usr/bin/postmaster`
- if [ $pid ] && /usr/bin/pg_ctl status -D $PGDATA > /dev/null 2>&1
- then
- echo $"Postmaster already running."
- else
- #all systems go -- remove any stale lock files
- rm -f /tmp/.s.PGSQL.${PGPORT} > /dev/null
- echo -n "$PSQL_START"
- 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
- sleep 1
- pid=`pidof -s /usr/bin/postmaster`
- if [ $pid ]
- then
- if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
- then
- success "$PSQL_START"
- else
- echo_success
- fi
- touch /var/lock/subsys/${NAME}
- echo $pid > /var/run/postmaster.pid
- echo
- else
- if echo "$TYPESET"|grep "declare -f failure ()" >/dev/null
- then
- failure "$PSQL_START"
- else
- echo_failure
- fi
- echo
- fi
- fi
- }
- stop(){
- echo -n $"Stopping ${NAME} service: "
- su -l -s /bin/sh -c "/usr/bin/pg_ctl stop -D $PGDATA -s -m fast" postgres > /dev/null 2>&1
- ret=$?
- if [ $ret -eq 0 ]
- then
- echo_success
- else
- echo_failure
- fi
- echo
- rm -f /var/run/postmaster.pid
- rm -f /var/lock/subsys/${NAME}
- }
- restart(){
- stop
- start
- }
- condrestart(){
- [ -e /var/lock/subsys/${NAME} ] && restart
- }
- reload(){
- su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl reload -D $PGDATA -s" > /dev/null 2>&1
- }
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status postmaster
- ;;
- restart)
- restart
- ;;
- condrestart)
- condrestart
- ;;
- reload|force-reload)
- reload
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
- exit 1
- esac
- exit 0
|