Convert to systemd startup support
This commit is contained in:
parent
7de7a32f91
commit
72893f4818
@ -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
|
||||
|
33
postgresql-pgctl-timeout.patch
Normal file
33
postgresql-pgctl-timeout.patch
Normal file
@ -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 */
|
||||
}
|
||||
}
|
199
postgresql-setup
Normal file
199
postgresql-setup
Normal file
@ -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
|
337
postgresql.init
337
postgresql.init
@ -1,337 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# postgresql This is the init script for starting up the PostgreSQL
|
||||
# server.
|
||||
#
|
||||
# This script is slightly unusual in that the name of the daemon (postmaster)
|
||||
# is not the same as the name of the subsystem (postgresql)
|
||||
#
|
||||
# chkconfig: - 64 36
|
||||
# description: PostgreSQL database server.
|
||||
# processname: postmaster
|
||||
# pidfile: /var/run/postmaster.PORT.pid
|
||||
### BEGIN INIT INFO
|
||||
# Provides: postgresql
|
||||
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
|
||||
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
|
||||
# Short-Description: start and stop PostgreSQL server
|
||||
# Description: PostgreSQL database server
|
||||
### END INIT INFO
|
||||
|
||||
# PGVERSION is the full package version, e.g., 9.0.2
|
||||
# Note: the specfile inserts the correct value during package build
|
||||
PGVERSION=xxxx
|
||||
# PGMAJORVERSION is major version, e.g., 9.0 (this should match PG_VERSION)
|
||||
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`
|
||||
# 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
|
||||
# PGDOCDIR is the directory containing the package's documentation
|
||||
# Note: the specfile inserts the correct value during package build
|
||||
PGDOCDIR=xxxx
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
# Get network config.
|
||||
. /etc/sysconfig/network
|
||||
|
||||
# Find the name of the script
|
||||
NAME=`basename $0`
|
||||
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
|
||||
then
|
||||
NAME=${NAME:3}
|
||||
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
|
||||
PGENGINE=/usr/bin
|
||||
PGPORT=5432
|
||||
PGDATA=/var/lib/pgsql/data
|
||||
PGLOG=/var/lib/pgsql/pgstartup.log
|
||||
# Value to set as postmaster process's oom_adj
|
||||
PG_OOM_ADJ=-17
|
||||
|
||||
# Override defaults from /etc/sysconfig/pgsql if file is present
|
||||
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
|
||||
|
||||
export PGDATA
|
||||
export PGPORT
|
||||
|
||||
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 4
|
||||
chown postgres:postgres "$PGLOG"
|
||||
chmod go-rwx "$PGLOG"
|
||||
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
|
||||
fi
|
||||
|
||||
# Check for the PGDATA structure
|
||||
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
|
||||
then
|
||||
# Check version of existing PGDATA
|
||||
if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
|
||||
then
|
||||
: A-OK
|
||||
elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
|
||||
then
|
||||
echo
|
||||
echo $"An old version of the database format was found."
|
||||
echo $"Use \"service postgresql upgrade\" to upgrade to version $PGMAJORVERSION."
|
||||
echo $"See $PGDOCDIR/README.rpm-dist for more information."
|
||||
exit 1
|
||||
else
|
||||
echo
|
||||
echo $"An old version of the database format was found."
|
||||
echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
|
||||
echo $"See $PGDOCDIR/README.rpm-dist for more information."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "$PSQL_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=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
|
||||
if [ "x$pid" != x ]
|
||||
then
|
||||
success "$PSQL_START"
|
||||
touch "$lockfile"
|
||||
echo $pid > "$pidfile"
|
||||
echo
|
||||
else
|
||||
failure "$PSQL_START"
|
||||
echo
|
||||
script_result=1
|
||||
fi
|
||||
}
|
||||
|
||||
stop(){
|
||||
echo -n $"Stopping ${NAME} service: "
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
restart(){
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
condrestart(){
|
||||
[ -e "$lockfile" ] && restart || :
|
||||
}
|
||||
|
||||
reload(){
|
||||
$SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
|
||||
}
|
||||
|
||||
# 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"
|
||||
|
||||
# Make sure the startup-time log file is OK, too
|
||||
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
|
||||
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 -n $"Data directory is not empty!"
|
||||
echo_failure
|
||||
echo
|
||||
script_result=1
|
||||
else
|
||||
echo -n $"Initializing database: "
|
||||
if perform_initdb
|
||||
then
|
||||
echo_success
|
||||
else
|
||||
echo_failure
|
||||
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_failure
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -x "$PGENGINE/pg_upgrade" ]
|
||||
then
|
||||
echo
|
||||
echo $"Please install the postgresql-upgrade RPM."
|
||||
echo_failure
|
||||
echo
|
||||
exit 5
|
||||
fi
|
||||
# Make sure service is stopped
|
||||
stop
|
||||
|
||||
echo -n $"Upgrading database: "
|
||||
|
||||
# Set up log file for pg_upgrade
|
||||
PGUPLOG=/var/lib/pgsql/pgupgrade.log
|
||||
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
|
||||
|
||||
# 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_success
|
||||
else
|
||||
# Clean up after failure
|
||||
rm -rf "$PGDATA"
|
||||
mv "$PGDATAOLD" "$PGDATA"
|
||||
|
||||
echo_failure
|
||||
fi
|
||||
echo
|
||||
echo $"See $PGUPLOG for details."
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status -p "$pidfile" postmaster
|
||||
script_result=$?
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
condrestart|try-restart)
|
||||
condrestart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
force-reload)
|
||||
restart
|
||||
;;
|
||||
initdb)
|
||||
initdb
|
||||
;;
|
||||
upgrade)
|
||||
upgrade
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb|upgrade}"
|
||||
exit 2
|
||||
esac
|
||||
|
||||
exit $script_result
|
36
postgresql.service
Normal file
36
postgresql.service
Normal file
@ -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
|
@ -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@redhat.com> 9.0.4-8
|
||||
- Convert to systemd startup support
|
||||
Resolves: #696427
|
||||
|
||||
* Thu Jul 21 2011 Petr Sabata <contyk@redhat.com> - 9.0.4-7
|
||||
- Perl mass rebuild
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user