diff --git a/postgresql.init b/postgresql.init index 386ef97..ad2e470 100644 --- a/postgresql.init +++ b/postgresql.init @@ -1,79 +1,18 @@ #!/bin/sh +# # postgresql This is the init script for starting up the PostgreSQL -# server +# server. # # chkconfig: - 64 36 -# description: Starts and stops the PostgreSQL backend daemon that handles \ -# all database requests. +# description: PostgreSQL database server. # processname: postmaster -# pidfile: /var/run/postmaster.pid +# pidfile: /var/run/postmaster.PORT.pid -# Version 6.5.3-2 Lamar Owen -# Added code to determine if PGDATA exists, whether it is current version -# or not, and initdb if no PGDATA (initdb will not overwrite a database). - -# Version 7.0 Lamar Owen -# Added logging code -# Changed PGDATA. - -# Version 7.0.2 Trond Eivind Glomsrd -# use functions, add conditional restart - -# Version 7.0.3 Lamar Owen -# Check for the existence of functions before blindly using them -# in particular -- check for success () and failure () before using. -# More Cross-distribution support -- PGVERSION variable, and docdir checks. - -# Version 7.1 Release Candidate Lamar Owen -# initdb parameters have changed. - -# Version 7.1.2 Trond Eivind Glomsrd -# Specify shell for su -# Handle stop better - kill unwanted output, make it wait until the database is ready -# Handle locales slightly differently - always using "C" isn't a valid option -# Kill output from database initialization -# Mark messages for translation - -# Version 7.1.2-2.PGDG Lamar Owen -# sync up. -# Karl's fixes for some quoting issues. - -# Version 7.2b2 Lamar Owen -# version change. - -# Version 7.2 final. Lamar Owen -# reload from Peter E. -# Eliminate the pidof postmaster test in stop -- we're using pg_ctl so we don't need pidof. -# Tested the $? return for the stop script -- it does in fact propagate. -# TODO: multiple postmasters. - -# Version 7.3 Lamar Owen -# Multiple postmasters, courtesy Karl DeBisschop - -# Version 7.4 Lamar Owen. - -# Version 7.4.3 Tom Lane -# Support condstop for uninstall -# Minor other changes suggested by Fernando Nasser. - -# Version 7.4.5 Tom Lane -# 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. - -# Version 8.1 Devrim Gunduz -# Increased sleep time from 1 sec to 2 sec. - -# Version 8.2 Devrim Gunduz -# Set initdb as a seperate option. - -# Version 8.3 Devrim Gunduz - -# Version 8.4 Devrim Gunduz -# Remove "sameuser" from initdb, to match the new hba conf file. +# This script is slightly unusual in that the name of the daemon (postmaster) +# is not the same as the name of the subsystem (postgresql) # PGVERSION is the full package version, e.g., 8.4.0 -# Note: the specfile ordinarily updates this during install +# Note: the specfile inserts the correct value during package build PGVERSION=xxxx # PGMAJORVERSION is major version, e.g., 8.4 (this should match PG_VERSION) PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'` @@ -81,10 +20,7 @@ PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'` # Source function library. . /etc/rc.d/init.d/functions -# Get function listing for cross-distribution logic. -TYPESET=`typeset -f|grep "declare"` - -# Get config. +# Get network config. . /etc/sysconfig/network # Find the name of the script @@ -117,21 +53,20 @@ PG_OOM_ADJ=-17 export PGDATA export PGPORT -# Check that networking is up. -# Pretty much need it for postmaster. -[ "${NETWORKING}" = "no" ] && exit 1 - -[ -f "$PGENGINE/postmaster" ] || exit 1 +lockfile="/var/lock/subsys/${NAME}" +pidfile="/var/run/postmaster.${PGPORT}.pid" script_result=0 start(){ + [ -x "$PGENGINE/postmaster" ] || exit 5 + PSQL_START=$"Starting ${NAME} service: " # Make sure startup-time log file is valid if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] then - touch "$PGLOG" || exit 1 + touch "$PGLOG" || exit 4 chown postgres:postgres "$PGLOG" chmod go-rwx "$PGLOG" [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" @@ -140,8 +75,7 @@ start(){ # Check for the PGDATA structure if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ] then - # Check version of existing PGDATA - + # Check version of existing PGDATA if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ] then SYSDOCDIR="(Your System's documentation directory)" @@ -167,10 +101,8 @@ start(){ echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information." exit 1 fi - - # No existing PGDATA! Warn the user to initdb it. - else + # No existing PGDATA! Warn the user to initdb it. echo echo "$PGDATA is missing. Use \"service postgresql initdb\" to initialize the cluster first." echo_failure @@ -182,12 +114,12 @@ start(){ test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_adj $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" ] + pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null` + if [ "x$pid" != x ] then success "$PSQL_START" - touch /var/lock/subsys/${NAME} - head -n 1 "$PGDATA/postmaster.pid" > "/var/run/postmaster.${PGPORT}.pid" + touch "$lockfile" + echo $pid > "$pidfile" echo else failure "$PSQL_START" @@ -198,18 +130,24 @@ start(){ 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 - ret=$? - if [ $ret -eq 0 ] + if [ -e "$lockfile" ] then + $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 + rm -f "$pidfile" + rm -f "$lockfile" + else echo_failure script_result=1 + fi + else + # not running; per LSB standards this is "ok" + echo_success fi echo - rm -f "/var/run/postmaster.${PGPORT}.pid" - rm -f "/var/lock/subsys/${NAME}" } restart(){ @@ -218,11 +156,7 @@ restart(){ } condrestart(){ - [ -e /var/lock/subsys/${NAME} ] && restart -} - -condstop(){ - [ -e /var/lock/subsys/${NAME} ] && stop + [ -e "$lockfile" ] && restart || : } reload(){ @@ -275,9 +209,6 @@ initdb(){ fi } -# This script is slightly unusual in that the name of the daemon (postmaster) -# is not the same as the name of the subsystem (postgresql) - # See how we were called. case "$1" in start) @@ -293,21 +224,21 @@ case "$1" in restart) restart ;; - condrestart) + condrestart|try-restart) condrestart ;; - condstop) - condstop - ;; - reload|force-reload) + reload) reload ;; + force-reload) + restart + ;; initdb) initdb ;; *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload|force-reload|initdb}" - exit 1 + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}" + exit 2 esac exit $script_result diff --git a/postgresql.spec b/postgresql.spec index 68b4a77..53a10d8 100755 --- a/postgresql.spec +++ b/postgresql.spec @@ -53,7 +53,7 @@ Summary: PostgreSQL client programs Name: postgresql %global majorversion 8.4 Version: 8.4.2 -Release: 7%{?dist} +Release: 8%{?dist} # The PostgreSQL license is very similar to other MIT licenses, but the OSI # recognizes it as an independent license, so we do as well. License: PostgreSQL @@ -170,10 +170,13 @@ PostgreSQL server. %package server Summary: The programs needed to create and run a PostgreSQL server Group: Applications/Databases -Requires: postgresql = %{version}-%{release} +Requires: %{name} = %{version}-%{release} Requires(pre): /usr/sbin/useradd -Requires(post): /sbin/chkconfig -Requires(preun): /sbin/chkconfig +Requires(post): chkconfig +Requires(preun): chkconfig +# This is for /sbin/service +Requires(preun): initscripts +Requires(postun): initscripts %description server The postgresql-server package includes the programs needed to create @@ -492,18 +495,18 @@ cat psql-%{majorversion}.lang >>main.lst %postun libs -p /sbin/ldconfig %pre server -groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : -useradd -M -N -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \ +/usr/sbin/groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : +/usr/sbin/useradd -M -N -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \ -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || : %post server -chkconfig --add postgresql +/sbin/chkconfig --add postgresql /sbin/ldconfig %preun server if [ $1 = 0 ] ; then - /sbin/service postgresql condstop >/dev/null 2>&1 - chkconfig --del postgresql + /sbin/service postgresql stop >/dev/null 2>&1 + /sbin/chkconfig --del postgresql fi %postun server @@ -711,6 +714,10 @@ rm -rf $RPM_BUILD_ROOT %endif %changelog +* Mon Feb 22 2010 Tom Lane 8.4.2-8 +- Bring init script into some modicum of compliance with Fedora/LSB standards +Resolves: #201043 + * Thu Feb 18 2010 Tom "spot" Callaway 8.4.2-7 - adjust license tag to reflect OSI decision