[postgresql] Convert to systemd startup support

Tom Lane tgl at fedoraproject.org
Wed Jul 27 23:33:28 UTC 2011


commit 72893f4818b3cec9525e7181472a672b496a70d0
Author: Tom Lane <tgl at redhat.com>
Date:   Wed Jul 27 19:32:24 2011 -0400

    Convert to systemd startup support

 README.rpm-dist                |   90 ++++++-----
 postgresql-pgctl-timeout.patch |   33 ++++
 postgresql-setup               |  199 +++++++++++++++++++++++
 postgresql.init                |  337 ----------------------------------------
 postgresql.service             |   36 +++++
 postgresql.spec                |   87 +++++++----
 6 files changed, 376 insertions(+), 406 deletions(-)
---
diff --git a/README.rpm-dist b/README.rpm-dist
index 38bdc9e..2795c31 100644
--- a/README.rpm-dist
+++ b/README.rpm-dist
@@ -36,18 +36,24 @@ QUICKSTART
 -----------------------------------------------------------------------------
 For a fresh installation, you will need to initialize the cluster first. Run:
 
-	service postgresql initdb
+	postgresql-setup initdb
 
 as root, and it will prepare a new database cluster for you. Then you will 
 need to start PostgreSQL. Again as root, run:
 
-	service postgresql start
+	systemctl start postgresql.service
 
 This command will start a postmaster that willl listen on localhost and Unix 
 socket 5432 only.  Edit /var/lib/pgsql/data/postgresql.conf and pg_hba.conf 
 if you want to allow remote access -- see the section on Grand Unified 
 Configuration.
 
+You will probably also want to do
+
+	systemctl enable postgresql.service
+
+so that the postmaster is automatically started during future reboots.
+
 The file /var/lib/pgsql/.bash_profile is packaged to help with the 
 setting of environment variables. You may edit this file, and it won't be
 overwritten during an upgrade.  However, enhancements and bugfixes may 
@@ -78,15 +84,15 @@ In some major releases, the RPMs also support in-place upgrade from the
 immediately previous major release.  Currently, you can upgrade in-place
 from 8.4.x to 9.0.x.  This is much faster than a dump and reload.
 To do an in-place upgrade:
-* shut down the old postmaster
+* shut down the old postmaster ("systemctl stop postgresql.service")
 * optionally make a backup of /var/lib/pgsql/data/
 * install the new version's RPMs (install all the ones you had before,
   plus postgresql-upgrade)
-* as root, run "service postgresql upgrade"
+* as root, run "postgresql-setup upgrade"
 * update the configuration files /var/lib/pgsql/data/*.conf with any
   customizations you had before (your old configuration files are in
   /var/lib/pgsql/data-old/)
-* as root, run "service postgresql start"
+* as root, run "systemctl start postgresql.service"
 * postgresql-upgrade can be removed after the update is complete
 
 NOTE: The in-place upgrade process is new and relatively poorly tested,
@@ -163,24 +169,29 @@ mailing list.
 
 MULTIPLE POSTMASTERS
 -------------------------------------------------------------------------------
-The postgresql-server RPM contains an 'initscript' that is used to start the
-postmaster.  The current version of this script has logic to be able to start
-multiple postmasters, with different data areas, listening on different ports,
-etc.  To use this functionality requires root access.
+The postgresql-server RPM contains a systemd "unit" file, postgresql.service,
+that is used to start the PostgreSQL postmaster.  If you need to run multiple
+postmasters on one machine, you should clone this file and modify it as
+necessary.
 
 As an example, let us create a secondary postmaster called, creatively enough,
 'secondary'.  Here are the steps:
-1.)	create a hard link in /etc/rc.d/init.d (or equivalent location)
-	to postgresql named 'secondary' : ln postgresql secondary   Pick
-	a name not already used in /etc/rc.d/init.d!
-2.)	create a file in /etc/sysconfig/pgsql named secondary.  This file is
-	a shell script -- typically you would define PGDATA, PGPORT, and PGOPTS
-	here.  Since $PGDATA/postgresql.conf will override many of these
-	settings, except PGDATA, you might be surprised on startup.
-3.)	create the target PGDATA.
-4.)	Initdb the target PGDATA with 'service secondary initdb'.
-5.)	Edit postgresql.conf to change the port, address, tcpip settings, etc.
-6.)	Start the postmaster with 'service secondary start'.
+1.)	Copy /lib/systemd/system/postgresql.service to
+	/etc/systemd/system/secondary.service.
+	(Note that user-created unit files must go into /etc not /lib!)
+2.)	Edit /etc/systemd/system/secondary.service to change the PGDATA and
+	PGPORT settings so they don't conflict with any other postmaster.
+3.)	Create the target PGDATA directory.
+4.)	Initdb the target PGDATA with 'postgresql-setup initdb secondary'.
+5.)	Edit postgresql.conf in the target PGDATA to change settings as needed.
+6.)	Start the new postmaster with 'systemctl start secondary.service'.
+	You will probably also want to do 'systemctl enable secondary.service'
+	so that the new postmaster is automatically started in future reboots.
+
+When doing a major-version upgrade of a secondary postmaster, mention the
+service name in the postgresql-setup command, for example 'postgresql-setup
+upgrade secondary'.  This will let postgresql-setup find the correct data
+directory from the service file.
 
 REGRESSION TESTING
 -------------------------------------------------------------------------------
@@ -189,10 +200,11 @@ regression tests.  These tests stress your database installation and produce
 results that give you assurances that the installation is complete, and that
 your database machine is up to the task.
 
-To run the regression tests under the RPM installation, make sure that
-postmaster has been started (if not, su to root and do "service postgresql
-start"), cd to /usr/lib/pgsql/test/regress (or /usr/lib64/pgsql/test/regress),
-su to postgres, and execute "make check".
+To run the regression tests under the RPM installation, make sure that the
+postmaster has been started (if not, su to root and do "systemctl start
+postgresql.service"), cd to /usr/lib/pgsql/test/regress (or
+/usr/lib64/pgsql/test/regress on a 64-bit machine), su to postgres,
+and execute "make check".
 This command will start the regression tests and will both show the
 results to the screen and store the results in the file regress.out.
 
@@ -207,24 +219,20 @@ script.
 
 STARTING POSTMASTER AUTOMATICALLY AT SYSTEM STARTUP
 -------------------------------------------------------------------------------
-Fedora / Red Hat / CentOS use the System V Init package.  A startup
-script for PostgreSQL is provided in the server package, as
-/etc/rc.d/init.d/postgresql.  To start the postmaster manually,
+Fedora / Red Hat / CentOS use the systemd package to manage server startup.
+A systemd unit file for PostgreSQL is provided in the server package, as
+/lib/systemd/system/postgresql.service.  To start the postmaster manually,
 as root run
-	service postgresql start
+	systemctl start postgresql.service
 To shut the postmaster down,
-	service postgresql stop
-There are other possible commands to this script -- execute
-'service postgresql' for a listing.
-
-To get this script to run at system startup or any time the system switches
-into runlevels 3, 4, or 5, run:
-	chkconfig --add postgresql
-	chkconfig --level 345 postgresql on
-and the proper symlinks will be created.  See the chkconfig man page for more
-information.  Note that this is manual -- while the startup script can include
-tags to allow chkconfig to automatically perform the symlinking, this is not
-done at this time.
+	systemctl stop postgresql.service
+These two commands only change the postmaster's current status.  If you
+want the postmaster to be started automatically during future system startups,
+run
+	systemctl enable postgresql.service
+To undo that again,
+	systemctl disable postgresql.service
+See "man systemctl" for other possible subcommands.
 
 GRAND UNIFIED CONFIGURATION (GUC) FILE
 -------------------------------------------------------------------------------
@@ -232,7 +240,7 @@ The PostgreSQL server has many tunable parameters -- the file
 /var/lib/pgsql/data/postgresql.conf is the master configuration file for the
 whole system.  
 
-The RPM ships with the default file -- you will need to tune the
+The RPM ships with a mostly-default file -- you will need to tune the
 parameters for your installation.  In particular, you might want to allow
 nonlocal TCP/IP socket connections -- in order to allow these, you will need
 to edit the postgresql.conf file.  The line in question contains the string 
diff --git a/postgresql-pgctl-timeout.patch b/postgresql-pgctl-timeout.patch
new file mode 100644
index 0000000..cfeb1a7
--- /dev/null
+++ b/postgresql-pgctl-timeout.patch
@@ -0,0 +1,33 @@
+Back-port a PG 9.1 logic change to allow "pg_ctl start -w" to fail in
+less than the -t timeout interval if the postmaster has clearly failed.
+This is the minimum needed to make it sane to use this method of launching
+the postmaster from a systemd service file.  9.1 will make this area
+considerably more robust.
+
+
+diff -Naur postgresql-9.0.4.orig/src/bin/pg_ctl/pg_ctl.c postgresql-9.0.4/src/bin/pg_ctl/pg_ctl.c
+--- postgresql-9.0.4.orig/src/bin/pg_ctl/pg_ctl.c	2011-04-14 23:15:53.000000000 -0400
++++ postgresql-9.0.4/src/bin/pg_ctl/pg_ctl.c	2011-07-27 18:32:05.547066731 -0400
+@@ -538,6 +538,22 @@
+ #endif
+ 				print_msg(".");
+ 
++			/*
++			 * The postmaster should create postmaster.pid very soon after
++			 * being started.  If it's not there after we've waited 5 or more
++			 * seconds, assume startup failed and give up waiting.  (This
++			 * won't cover cases where the postmaster crashes after creating
++			 * the file, nor where there's a pre-existing postmaster, but
++			 * it's better than nothing.)
++			 */
++			if (i >= 5)
++			{
++				struct stat statbuf;
++
++				if (stat(pid_file, &statbuf) != 0)
++					break;
++			}
++
+ 			pg_usleep(1000000); /* 1 sec */
+ 		}
+ 	}
diff --git a/postgresql-setup b/postgresql-setup
new file mode 100644
index 0000000..8b2a9ce
--- /dev/null
+++ b/postgresql-setup
@@ -0,0 +1,199 @@
+#!/bin/sh
+#
+# postgresql-setup	Initialization and upgrade operations for PostgreSQL
+
+# PGVERSION is the full package version, e.g., 9.0.2
+# Note: the specfile inserts the correct value during package build
+PGVERSION=xxxx
+# PGENGINE is the directory containing the postmaster executable
+# Note: the specfile inserts the correct value during package build
+PGENGINE=xxxx
+# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades
+# Note: the specfile inserts the correct value during package build
+PREVMAJORVERSION=xxxx
+# PREVPGENGINE is the directory containing the previous postmaster executable
+# Note: the specfile inserts the correct value during package build
+PREVPGENGINE=xxxx
+
+# Absorb configuration settings from the specified systemd service file,
+# or the default "postgresql" service if not specified
+SERVICE_NAME="$2"
+if [ x"$SERVICE_NAME" = x ]
+then
+    SERVICE_NAME=postgresql
+fi
+
+if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
+then
+    SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
+elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
+then
+    SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
+else
+    echo "Could not find systemd unit file ${SERVICE_NAME}.service"
+    exit 1
+fi
+
+# Get port number and data directory from the service file
+PGPORT=`sed -n 's/Environment=PGPORT=//p' "${SERVICE_FILE}"`
+PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`
+
+# Log file for initdb
+PGLOG=/var/lib/pgsql/initdb.log
+
+# Log file for pg_upgrade
+PGUPLOG=/var/lib/pgsql/pgupgrade.log
+
+export PGPORT
+export PGDATA
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+script_result=0
+
+# code shared between initdb and upgrade actions
+perform_initdb(){
+	if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
+	then
+		mkdir -p "$PGDATA" || return 1
+		chown postgres:postgres "$PGDATA"
+		chmod go-rwx "$PGDATA"
+	fi
+	# Clean up SELinux tagging for PGDATA
+	[ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"
+
+	# Create the initdb log file if needed
+	if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
+	then
+		touch "$PGLOG" || return 1
+		chown postgres:postgres "$PGLOG"
+		chmod go-rwx "$PGLOG"
+		[ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
+	fi
+
+	# Initialize the database
+	$SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null
+
+	# Create directory for postmaster log files
+	mkdir "$PGDATA/pg_log"
+	chown postgres:postgres "$PGDATA/pg_log"
+	chmod go-rwx "$PGDATA/pg_log"
+
+	if [ -f "$PGDATA/PG_VERSION" ]
+	then
+	    return 0
+	fi
+	return 1
+}
+
+initdb(){
+    if [ -f "$PGDATA/PG_VERSION" ]
+    then
+	echo $"Data directory is not empty!"
+	echo
+	script_result=1
+    else
+	echo -n $"Initializing database ... "
+	if perform_initdb
+	then
+	    echo $"OK"
+	else
+	    echo $"failed, see $PGLOG"
+	    script_result=1
+	fi
+	echo
+    fi
+}
+
+upgrade(){
+    # must see previous version in PG_VERSION
+    if [ ! -f "$PGDATA/PG_VERSION" -o \
+	 x`cat "$PGDATA/PG_VERSION"` != x"$PREVMAJORVERSION" ]
+    then
+	echo
+	echo $"Cannot upgrade because database is not of version $PREVMAJORVERSION."
+	echo
+	exit 1
+    fi
+    if [ ! -x "$PGENGINE/pg_upgrade" ]
+    then
+	echo
+	echo $"Please install the postgresql-upgrade RPM."
+	echo
+	exit 5
+    fi
+
+    # Make sure service is stopped
+    # Using service here makes it work both with systemd and other init systems
+    service "$SERVICE_NAME" stop
+
+    # Set up log file for pg_upgrade
+    rm -f "$PGUPLOG"
+    touch "$PGUPLOG" || exit 1
+    chown postgres:postgres "$PGUPLOG"
+    chmod go-rwx "$PGUPLOG"
+    [ -x /sbin/restorecon ] && /sbin/restorecon "$PGUPLOG"
+
+    # Move old DB to PGDATAOLD
+    PGDATAOLD="${PGDATA}-old"
+    rm -rf "$PGDATAOLD"
+    mv "$PGDATA" "$PGDATAOLD" || exit 1
+
+    echo -n $"Upgrading database: "
+
+    # Create empty new-format database
+    if perform_initdb
+    then
+	# Do the upgrade
+	$SU -l postgres -c "$PGENGINE/pg_upgrade \
+		'--old-bindir=$PREVPGENGINE' \
+		'--new-bindir=$PGENGINE' \
+		'--old-datadir=$PGDATAOLD' \
+		'--new-datadir=$PGDATA' \
+		--link \
+		'--old-port=$PGPORT' '--new-port=$PGPORT' \
+		--user=postgres" >> "$PGUPLOG" 2>&1 < /dev/null
+	if [ $? -ne 0 ]
+	then
+	    # pg_upgrade failed
+	    script_result=1
+	fi
+    else
+	# initdb failed
+	script_result=1
+    fi
+
+    if [ $script_result -eq 0 ]
+    then
+	    echo $"OK"
+    else
+	    # Clean up after failure
+	    rm -rf "$PGDATA"
+	    mv "$PGDATAOLD" "$PGDATA"
+
+	    echo $"failed"
+    fi
+    echo
+    echo $"See $PGUPLOG for details."
+}
+
+# See how we were called.
+case "$1" in
+  initdb)
+	initdb
+	;;
+  upgrade)
+	upgrade
+	;;
+  *)
+	echo $"Usage: $0 {initdb|upgrade} [ service_name ]"
+	exit 2
+esac
+
+exit $script_result
diff --git a/postgresql.service b/postgresql.service
new file mode 100644
index 0000000..0c733bd
--- /dev/null
+++ b/postgresql.service
@@ -0,0 +1,36 @@
+[Unit]
+Description=PostgreSQL database server
+After=syslog.target
+After=network.target
+
+[Service]
+Type=forking
+
+User=postgres
+Group=postgres
+
+# Note: avoid inserting whitespace in these Environment= lines, or you may
+# break postgresql-setup.
+
+# Port number for server to listen on
+Environment=PGPORT=5432
+
+# Location of database directory
+Environment=PGDATA=/var/lib/pgsql/data
+
+# Where to send early-startup messages from the server (before the logging
+# options of postgresql.conf take effect)
+StandardOutput=syslog
+
+# Disable OOM kill on the postmaster
+OOMScoreAdjust=-1000
+
+ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
+ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast
+ExecReload=/usr/bin/pg_ctl reload -D ${PGDATA} -s
+
+# Give a reasonable amount of time for the server to start up/shut down
+TimeoutSec=300
+
+[Install]
+WantedBy=multi-user.target
diff --git a/postgresql.spec b/postgresql.spec
index d874f80..1e18d70 100644
--- a/postgresql.spec
+++ b/postgresql.spec
@@ -54,7 +54,10 @@ Summary: PostgreSQL client programs
 Name: postgresql
 %global majorversion 9.0
 Version: 9.0.4
-Release: 7%{?dist}
+Release: 8%{?dist}
+# Update this whenever F15 gets rebased; it must be NVR-greater than F15 pkg:
+%global first_systemd_version 9.0.4-8
+
 # 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
@@ -73,11 +76,12 @@ Source1: postgresql-%{version}-US.pdf
 # generate-pdf.sh is not used during RPM build, but include for documentation
 Source2: generate-pdf.sh
 Source3: ftp://ftp.postgresql.org/pub/source/v%{prevversion}/postgresql-%{prevversion}.tar.bz2
-Source4: postgresql.init
 Source5: Makefile.regress
 Source6: pg_config.h
 Source7: ecpg_config.h
 Source8: README.rpm-dist
+Source9: postgresql-setup
+Source10: postgresql.service
 Source14: postgresql.pam
 Source15: postgresql-bashprofile
 
@@ -87,12 +91,12 @@ Patch2: postgresql-logging.patch
 Patch3: postgresql-perl-rpath.patch
 Patch4: postgresql-gcc-workaround.patch
 Patch5: postgresql-perl-5.14.patch
+Patch6: postgresql-pgctl-timeout.patch
 
 BuildRequires: perl(ExtUtils::MakeMaker) glibc-devel bison flex gawk
 BuildRequires: perl(ExtUtils::Embed), perl-devel
-# for /sbin/ldconfig
-Requires(post): glibc initscripts
-Requires(postun): glibc initscripts
+BuildRequires: readline-devel zlib-devel
+BuildRequires: systemd-units
 
 %if %plpython
 BuildRequires: python-devel
@@ -105,9 +109,6 @@ BuildRequires: tcl-devel
 %endif
 %endif
 
-BuildRequires: readline-devel
-BuildRequires: zlib-devel >= 1.0.4
-
 %if %ssl
 BuildRequires: openssl-devel
 %endif
@@ -167,6 +168,9 @@ if you're installing the postgresql-server package.
 Summary: The shared libraries required for any PostgreSQL clients
 Group: Applications/Databases
 Provides: libpq.so = %{version}-%{release}
+# for /sbin/ldconfig
+Requires(post): glibc
+Requires(postun): glibc
 
 %description libs
 The postgresql-libs package provides the essential shared libraries for any 
@@ -180,11 +184,18 @@ Group: Applications/Databases
 Requires: %{name}%{?_isa} = %{version}-%{release}
 Requires: %{name}-libs%{?_isa} = %{version}-%{release}
 Requires(pre): /usr/sbin/useradd
+# for /sbin/ldconfig
+Requires(post): glibc
+Requires(postun): glibc
+# pre/post stuff needs systemd too
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+# This is actually needed for the %%triggerun script but Requires(triggerun)
+# is not valid.  We can use post because this particular %%triggerun script
+# should fire just after this package is installed.
+Requires(post): systemd-sysv
 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
@@ -306,6 +317,7 @@ system, including regression tests and benchmarks.
 %patch3 -p1
 %patch4 -p1
 %patch5 -p1
+%patch6 -p1
 
 # We used to run autoconf here, but there's no longer any real need to,
 # since Postgres ships with a reasonably modern configure script.
@@ -388,7 +400,6 @@ CFLAGS="$CFLAGS -DLINUX_OOM_ADJ=0"
 	--enable-thread-safety \
 %endif
 	--with-system-tzdata=/usr/share/zoneinfo \
-	--sysconfdir=/etc/sysconfig/pgsql \
 	--datadir=/usr/share/pgsql
 
 make %{?_smp_mflags} world
@@ -452,14 +463,16 @@ esac
 install -d -m 755 $RPM_BUILD_ROOT%{_libdir}/pgsql/tutorial
 cp src/tutorial/* $RPM_BUILD_ROOT%{_libdir}/pgsql/tutorial
 
-# prep the initscript, including insertion of some values it needs
-install -d $RPM_BUILD_ROOT/etc/rc.d/init.d
+# prep the setup script, including insertion of some values it needs
 sed -e 's|^PGVERSION=.*$|PGVERSION=%{version}|' \
+	-e 's|^PGENGINE=.*$|PGENGINE=%{_bindir}|' \
 	-e 's|^PREVMAJORVERSION=.*$|PREVMAJORVERSION=%{prevmajorversion}|' \
 	-e 's|^PREVPGENGINE=.*$|PREVPGENGINE=%{_libdir}/pgsql/postgresql-%{prevmajorversion}/bin|' \
-	-e 's|^PGDOCDIR=.*$|PGDOCDIR=%{_docdir}/%{name}-%{version}|' \
-	<%{SOURCE4} >postgresql.init
-install -m 755 postgresql.init $RPM_BUILD_ROOT/etc/rc.d/init.d/postgresql
+	<%{SOURCE9} >postgresql-setup
+install -m 755 postgresql-setup $RPM_BUILD_ROOT%{_bindir}/postgresql-setup
+
+install -d $RPM_BUILD_ROOT%{_unitdir}
+install -m 644 %{SOURCE10} $RPM_BUILD_ROOT%{_unitdir}/postgresql.service
 
 %if %pam
 install -d $RPM_BUILD_ROOT/etc/pam.d
@@ -475,9 +488,6 @@ install -d -m 700 $RPM_BUILD_ROOT/var/lib/pgsql/backups
 # postgres' .bash_profile
 install -m 644 %{SOURCE15} $RPM_BUILD_ROOT/var/lib/pgsql/.bash_profile
 
-# Create the multiple postmaster startup directory
-install -d -m 700 $RPM_BUILD_ROOT/etc/sysconfig/pgsql
-
 
 %if %upgrade
 	pushd postgresql-%{prevversion}
@@ -593,19 +603,36 @@ cat psql-%{majorversion}.lang >>main.lst
 	-c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || :
 
 %post server
-/sbin/chkconfig --add postgresql
 /sbin/ldconfig
+if [ $1 -eq 1 ] ; then
+    # Initial installation
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+
+# Run this when upgrading from SysV initscript to native systemd unit
+%triggerun server -- postgresql-server < %{first_systemd_version}
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply postgresql
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save postgresql >/dev/null 2>&1 || :
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del postgresql >/dev/null 2>&1 || :
+/bin/systemctl try-restart postgresql.service >/dev/null 2>&1 || :
 
 %preun server
-if [ $1 = 0 ] ; then
-	/sbin/service postgresql stop >/dev/null 2>&1
-	/sbin/chkconfig --del postgresql
+if [ $1 -eq 0 ] ; then
+    # Package removal, not upgrade
+    /bin/systemctl --no-reload disable postgresql.service >/dev/null 2>&1 || :
+    /bin/systemctl stop postgresql.service >/dev/null 2>&1 || :
 fi
 
 %postun server
 /sbin/ldconfig 
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
 if [ $1 -ge 1 ] ; then
-	/sbin/service postgresql condrestart >/dev/null 2>&1 || :
+    # Package upgrade, not uninstall
+    /bin/systemctl try-restart postgresql.service >/dev/null 2>&1 || :
 fi
 
 %if %plperl
@@ -734,17 +761,17 @@ rm -rf $RPM_BUILD_ROOT
 
 %files server -f server.lst
 %defattr(-,root,root)
-/etc/rc.d/init.d/postgresql
+%{_unitdir}/postgresql.service
 %if %pam
 %config(noreplace) /etc/pam.d/postgresql
 %endif
-%attr (755,root,root) %dir /etc/sysconfig/pgsql
 %{_bindir}/initdb
 %{_bindir}/pg_controldata
 %{_bindir}/pg_ctl
 %{_bindir}/pg_resetxlog
 %{_bindir}/postgres
 %{_bindir}/postmaster
+%{_bindir}/postgresql-setup
 %{_mandir}/man1/initdb.*
 %{_mandir}/man1/pg_controldata.*
 %{_mandir}/man1/pg_ctl.*
@@ -824,6 +851,10 @@ rm -rf $RPM_BUILD_ROOT
 %endif
 
 %changelog
+* Wed Jul 27 2011 Tom Lane <tgl at redhat.com> 9.0.4-8
+- Convert to systemd startup support
+Resolves: #696427
+
 * Thu Jul 21 2011 Petr Sabata <contyk at redhat.com> - 9.0.4-7
 - Perl mass rebuild
 


More information about the scm-commits mailing list