Solve stale-lockfile problem; use runuser instead of su.

This commit is contained in:
Tom Lane 2004-10-05 15:32:24 +00:00
parent 0c2148cdc2
commit 3fd417a317
2 changed files with 34 additions and 28 deletions

View File

@ -56,6 +56,11 @@
# Support condstop for uninstall # Support condstop for uninstall
# Minor other changes suggested by Fernando Nasser. # Minor other changes suggested by Fernando Nasser.
# Version 7.4.5 Tom Lane <tgl@sss.pgh.pa.us>
# Rewrite to start postmaster directly, rather than via pg_ctl; this avoids
# fooling the postmaster's stale-lockfile check by having too many
# postgres-owned processes laying about.
# PGVERSION is: # PGVERSION is:
PGVERSION=7.4 PGVERSION=7.4
@ -77,6 +82,14 @@ then
NAME=${NAME:3} NAME=${NAME:3}
fi fi
# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
SU=runuser
else
SU=su
fi
# Set defaults for configuration variables # Set defaults for configuration variables
PGENGINE=/usr/bin PGENGINE=/usr/bin
@ -157,45 +170,34 @@ start(){
[ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n [ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
# Just in case no locale was set, use en_US # Just in case no locale was set, use en_US
[ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n [ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
# Is expanded this early to be used in the command su runs # 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 echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
# Initialize the database # Initialize the database
su -l postgres -c "$PGENGINE/initdb --pgdata=$PGDATA" >> $PGLOG 2>&1 < /dev/null $SU -l postgres -c "$PGENGINE/initdb --pgdata=$PGDATA" >> $PGLOG 2>&1 < /dev/null
[ -f $PGDATA/PG_VERSION ] && echo_success [ -f $PGDATA/PG_VERSION ] && echo_success
[ ! -f $PGDATA/PG_VERSION ] && echo_failure [ ! -f $PGDATA/PG_VERSION ] && echo_failure
echo echo
fi 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 $PGENGINE/postmaster`
if [ $pid ] && $PGENGINE/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" echo -n "$PSQL_START"
su -l postgres -c "$PGENGINE/pg_ctl -D $PGDATA -p $PGENGINE/postmaster -o '-p ${PGPORT} ${PGOPTS}' start" >> $PGLOG 2>&1 < /dev/null $SU -l postgres -c "$PGENGINE/postmaster -p ${PGPORT} -D '${PGDATA}' ${PGOPTS} &" >> $PGLOG 2>&1 < /dev/null
sleep 1 sleep 1
pid=`pidof -s $PGENGINE/postmaster` pid=`pidof -s $PGENGINE/postmaster`
if [ $pid ] if [ $pid ] && [ -f "${PGDATA}/postmaster.pid" ]
then then
success "$PSQL_START" success "$PSQL_START"
touch /var/lock/subsys/${NAME} touch /var/lock/subsys/${NAME}
echo $pid > /var/run/postmaster.${PGPORT}.pid head -n 1 "${PGDATA}/postmaster.pid" > /var/run/postmaster.${PGPORT}.pid
echo echo
else else
failure "$PSQL_START" failure "$PSQL_START"
echo echo
fi fi
fi
} }
stop(){ stop(){
echo -n $"Stopping ${NAME} service: " 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=$? ret=$?
if [ $ret -eq 0 ] if [ $ret -eq 0 ]
then then
@ -222,7 +224,7 @@ condstop(){
} }
reload(){ 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) # This script is slightly unusual in that the name of the daemon (postmaster)
@ -257,4 +259,3 @@ case "$1" in
esac esac
exit 0 exit 0

View File

@ -67,7 +67,7 @@ Version: 7.4.5
# Pre-release RPM's should not be put up on the public ftp.postgresql.org server # Pre-release RPM's should not be put up on the public ftp.postgresql.org server
# -- only test releases or full releases should be. # -- only test releases or full releases should be.
Release: 2 Release: 3
License: BSD License: BSD
Group: Applications/Databases Group: Applications/Databases
Source0: ftp://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.bz2 Source0: ftp://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.bz2
@ -84,6 +84,7 @@ Source18: ftp://ftp.druid.net/pub/distrib/PyGreSQL-3.5.tgz
Patch1: rpm-pgsql-7.4.patch Patch1: rpm-pgsql-7.4.patch
Patch2: rpm-multilib-%{version}.patch Patch2: rpm-multilib-%{version}.patch
Patch3: postgresql-7.4-tighten.patch Patch3: postgresql-7.4-tighten.patch
Patch4: postgresql-7.4-getppid.patch
Patch5: postgresql-plperl.patch Patch5: postgresql-plperl.patch
Patch6: postgresql-7.4-src-tutorial.patch Patch6: postgresql-7.4-src-tutorial.patch
Patch7: postgresql-7.3.4-s390-pic.patch Patch7: postgresql-7.3.4-s390-pic.patch
@ -331,7 +332,7 @@ popd
%patch1 -p1 %patch1 -p1
%patch2 -p1 %patch2 -p1
%patch3 -p1 %patch3 -p1
# %patch4 -p1 %patch4 -p1
%patch5 -p1 %patch5 -p1
%patch6 -p1 %patch6 -p1
%patch7 -p1 %patch7 -p1
@ -784,6 +785,10 @@ rm -rf $RPM_BUILD_ROOT
%endif %endif
%changelog %changelog
* Tue Oct 05 2004 Tom Lane <tgl@redhat.com> 7.4.5-3
- Solve the stale lockfile problem (bugs 71295, 96981, 134090)
- Use runuser instead of su for SELinux (bug 134588)
* Mon Aug 30 2004 Tom Lane <tgl@redhat.com> 7.4.5-2 * Mon Aug 30 2004 Tom Lane <tgl@redhat.com> 7.4.5-2
- Update to PyGreSQL 3.5. - Update to PyGreSQL 3.5.