summaryrefslogtreecommitdiffstats
path: root/postgresql.init
diff options
context:
space:
mode:
Diffstat (limited to 'postgresql.init')
-rw-r--r--postgresql.init99
1 files changed, 52 insertions, 47 deletions
diff --git a/postgresql.init b/postgresql.init
index 65c3ed4..89ef562 100644
--- a/postgresql.init
+++ b/postgresql.init
@@ -63,7 +63,7 @@
# PGVERSION is:
-PGVERSION=7.4
+PGVERSION=8.0
# Source function library.
INITD=/etc/rc.d/init.d
@@ -94,121 +94,125 @@ fi
# Set defaults for configuration variables
PGENGINE=/usr/bin
PGPORT=5432
-export PGDATA=/var/lib/pgsql
-if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base/template1 ]
+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
+ PGDATA=/var/lib/pgsql/data
fi
-PGLOG=/dev/null
+PGLOG=/var/lib/pgsql/pgstartup.log
# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
+
export PGDATA
export PGPORT
-export PGOPTS
# Check that networking is up.
# Pretty much need it for postmaster.
[ "${NETWORKING}" = "no" ] && exit 0
-[ -f $PGENGINE/postmaster ] || exit 0
+[ -f "$PGENGINE/postmaster" ] || exit 1
+
+script_result=0
start(){
PSQL_START=$"Starting ${NAME} service: "
+ # Make sure startup-time log file is valid
+ if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
+ then
+ touch "$PGLOG" || exit 1
+ chown postgres:postgres "$PGLOG"
+ chmod go-rwx "$PGLOG"
+ [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$PGLOG"
+ fi
+
# Check for the PGDATA structure
- if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
+ if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
then
# Check version of existing PGDATA
- if [ `cat $PGDATA/PG_VERSION` != "$PGVERSION" ]
+ if [ `cat "$PGDATA/PG_VERSION"` != "$PGVERSION" ]
then
SYSDOCDIR="(Your System's documentation directory)"
- if [ -d /usr/doc/postgresql-$PGVERSION ]
+ if [ -d "/usr/doc/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/doc
fi
- if [ -d /usr/share/doc/postgresql-$PGVERSION ]
+ if [ -d "/usr/share/doc/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/share/doc
fi
- if [ -d /usr/doc/packages/postgresql-$PGVERSION ]
+ if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/doc/packages
fi
- if [ -d /usr/share/doc/packages/postgresql-$PGVERSION ]
+ if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/share/doc/packages
fi
echo
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."
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 [ ! -e $PGDATA -a ! -h $PGDATA ]
+ echo -n $"Initializing database: "
+ if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
then
- mkdir -p $PGDATA || exit 1
- chown postgres:postgres $PGDATA
- chmod go-rwx $PGDATA
- [ -x /sbin/restorecon ] && restorecon -R $PGDATA
+ mkdir -p "$PGDATA" || exit 1
+ 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
+ # Clean up SELinux tagging for PGDATA
+ [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"
# Initialize the database
- $SU -l postgres -c "$PGENGINE/initdb --pgdata=$PGDATA" >> $PGLOG 2>&1 < /dev/null
- [ -f $PGDATA/PG_VERSION ] && echo_success
- [ ! -f $PGDATA/PG_VERSION ] && echo_failure
+ $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident sameuser'" >> "$PGLOG" 2>&1 < /dev/null
+ # Create directory for postmaster log
+ mkdir "$PGDATA/pg_log"
+ chown postgres:postgres "$PGDATA/pg_log"
+ chmod go-rwx "$PGDATA/pg_log"
+
+ [ -f "$PGDATA/PG_VERSION" ] && echo_success
+ [ ! -f "$PGDATA/PG_VERSION" ] && echo_failure
echo
fi
echo -n "$PSQL_START"
- $SU -l postgres -c "$PGENGINE/postmaster -p ${PGPORT} -D '${PGDATA}' ${PGOPTS} &" >> $PGLOG 2>&1 < /dev/null
- sleep 1
- pid=`pidof -s $PGENGINE/postmaster`
- if [ $pid ] && [ -f "${PGDATA}/postmaster.pid" ]
+ $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
+ sleep 2
+ pid=`pidof -s "$PGENGINE/postmaster"`
+ if [ $pid ] && [ -f "$PGDATA/postmaster.pid" ]
then
success "$PSQL_START"
touch /var/lock/subsys/${NAME}
- head -n 1 "${PGDATA}/postmaster.pid" > /var/run/postmaster.${PGPORT}.pid
+ head -n 1 "$PGDATA/postmaster.pid" > "/var/run/postmaster.${PGPORT}.pid"
echo
else
failure "$PSQL_START"
echo
+ script_result=1
fi
}
stop(){
echo -n $"Stopping ${NAME} service: "
- $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '${PGDATA}' -s -m fast" > /dev/null 2>&1 < /dev/null
+ $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null
ret=$?
if [ $ret -eq 0 ]
then
echo_success
else
echo_failure
+ script_result=1
fi
echo
- rm -f /var/run/postmaster.${PGPORT}.pid
- rm -f /var/lock/subsys/${NAME}
+ rm -f "/var/run/postmaster.${PGPORT}.pid"
+ rm -f "/var/lock/subsys/${NAME}"
}
restart(){
@@ -225,7 +229,7 @@ condstop(){
}
reload(){
- $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '${PGDATA}' -s" > /dev/null 2>&1 < /dev/null
+ $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
}
# This script is slightly unusual in that the name of the daemon (postmaster)
@@ -241,6 +245,7 @@ case "$1" in
;;
status)
status postmaster
+ script_result=$?
;;
restart)
restart
@@ -259,4 +264,4 @@ case "$1" in
exit 1
esac
-exit 0
+exit $script_result