aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-11-07 09:12:09 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2012-11-07 09:12:09 +0000
commit558388f10a0fd7b392d8ab5761ccfddf79485ede (patch)
tree528f0c4558792d25fd50168e6c23ef649c63397c
parentb3b060d72e80703b36092bce96ad5490b313eeb7 (diff)
downloadalpine_aports-558388f10a0fd7b392d8ab5761ccfddf79485ede.tar.bz2
alpine_aports-558388f10a0fd7b392d8ab5761ccfddf79485ede.tar.xz
alpine_aports-558388f10a0fd7b392d8ab5761ccfddf79485ede.zip
main/postgresql: fix init scripts for 9.2
- change some variables, {NICE,RUDE,FORCE}_TIMEOUT to correspond with gentoo variables, while still beeing backawards compatible - change data dir to 9.2 - patch initdb to not suggest how to start postgresql
-rw-r--r--main/postgresql/APKBUILD24
-rw-r--r--main/postgresql/initdb.patch18
-rw-r--r--main/postgresql/pg-restore.initd9
-rw-r--r--main/postgresql/postgresql.confd87
-rw-r--r--main/postgresql/postgresql.initd124
5 files changed, 148 insertions, 114 deletions
diff --git a/main/postgresql/APKBUILD b/main/postgresql/APKBUILD
index e792fcd2f7..d77f797c1e 100644
--- a/main/postgresql/APKBUILD
+++ b/main/postgresql/APKBUILD
@@ -1,7 +1,7 @@
1# Maintainer: Natanael Copa <ncopa@alpinelinux.org> 1# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
2pkgname=postgresql 2pkgname=postgresql
3pkgver=9.2.1 3pkgver=9.2.1
4pkgrel=0 4pkgrel=1
5pkgdesc="A sophisticated object-relational DBMS" 5pkgdesc="A sophisticated object-relational DBMS"
6url="http://www.postgresql.org/" 6url="http://www.postgresql.org/"
7arch="all" 7arch="all"
@@ -11,15 +11,26 @@ install="$pkgname.pre-upgrade"
11depends_dev="readline-dev openssl-dev zlib-dev libxml2-dev" 11depends_dev="readline-dev openssl-dev zlib-dev libxml2-dev"
12makedepends="$depends_dev" 12makedepends="$depends_dev"
13subpackages="$pkgname-dev $pkgname-doc libpq $pkgname-client" 13subpackages="$pkgname-dev $pkgname-doc libpq $pkgname-client"
14patches="initdb.patch"
14source="ftp://ftp.$pkgname.org/pub/source/v$pkgver/$pkgname-$pkgver.tar.bz2 15source="ftp://ftp.$pkgname.org/pub/source/v$pkgver/$pkgname-$pkgver.tar.bz2
16 $patches
15 $pkgname.initd 17 $pkgname.initd
16 $pkgname.confd 18 $pkgname.confd
17 pg-restore.initd 19 pg-restore.initd
18 pg-restore.confd 20 pg-restore.confd
19 " 21 "
20 22
23_builddir="$srcdir"/$pkgname-$pkgver
24prepare() {
25 cd "$_builddir"
26 for i in $patches; do
27 msg $i
28 patch -p1 -i "$srcdir"/$i || return 1
29 done
30}
31
21build() { 32build() {
22 cd "$srcdir"/$pkgname-$pkgver || return 1 33 cd "$_builddir"
23 ./configure --prefix=/usr \ 34 ./configure --prefix=/usr \
24 --mandir=/usr/share/man \ 35 --mandir=/usr/share/man \
25 --with-openssl \ 36 --with-openssl \
@@ -29,7 +40,7 @@ build() {
29} 40}
30 41
31package() { 42package() {
32 cd "$srcdir"/$pkgname-$pkgver || return 1 43 cd "$_builddir"
33 make DESTDIR="$pkgdir" install install-docs || return 1 44 make DESTDIR="$pkgdir" install install-docs || return 1
34 45
35 install -D -m755 "$srcdir"/postgresql.initd \ 46 install -D -m755 "$srcdir"/postgresql.initd \
@@ -58,7 +69,8 @@ client() {
58 69
59 70
60md5sums="c0b4799ea9850eae3ead14f0a60e9418 postgresql-9.2.1.tar.bz2 71md5sums="c0b4799ea9850eae3ead14f0a60e9418 postgresql-9.2.1.tar.bz2
614d2f5be74fae4895db3d993e69bbda10 postgresql.initd 72de29e4cea00a3318a77587fbbc7b6243 initdb.patch
62b609795f715cefcc30b08e4ed01f4416 postgresql.confd 7301cc8d4a4cbc77a7b6f84344155232d5 postgresql.initd
63df2d90fc713b4e89fd21abb9e36cd688 pg-restore.initd 74ca9759d29dc86402858821d5fdec48a1 postgresql.confd
75d2a51db4436e550d56bb1e96699faef4 pg-restore.initd
64bf45384752b320b369f1425939763178 pg-restore.confd" 76bf45384752b320b369f1425939763178 pg-restore.confd"
diff --git a/main/postgresql/initdb.patch b/main/postgresql/initdb.patch
new file mode 100644
index 0000000000..f2fad3f028
--- /dev/null
+++ b/main/postgresql/initdb.patch
@@ -0,0 +1,18 @@
1--- ./src/bin/initdb/initdb.c.orig
2+++ ./src/bin/initdb/initdb.c
3@@ -3317,14 +3317,6 @@
4 strlcpy(bin_dir, argv[0], sizeof(bin_dir));
5 get_parent_directory(bin_dir);
6
7- printf(_("\nSuccess. You can now start the database server using:\n\n"
8- " %s%s%spostgres%s -D %s%s%s\n"
9- "or\n"
10- " %s%s%spg_ctl%s -D %s%s%s -l logfile start\n\n"),
11- QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
12- QUOTE_PATH, pg_data_native, QUOTE_PATH,
13- QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
14- QUOTE_PATH, pg_data_native, QUOTE_PATH);
15-
16+ printf(_("\nSuccess.\n\n"));
17 return 0;
18 }
diff --git a/main/postgresql/pg-restore.initd b/main/postgresql/pg-restore.initd
index 1cc4da5c8f..f6075bca2d 100644
--- a/main/postgresql/pg-restore.initd
+++ b/main/postgresql/pg-restore.initd
@@ -1,8 +1,6 @@
1#!/sbin/runscript 1#!/sbin/runscript
2 2
3. /etc/conf.d/postgresql 3extra_commands="${opts} dump restore purge"
4
5opts="${opts} dump restore purge"
6 4
7depend() { 5depend() {
8 need postgresql 6 need postgresql
@@ -12,11 +10,10 @@ restore() {
12 yesno "$PGDUMP" && return 0 10 yesno "$PGDUMP" && return 0
13 ebegin "Restoring PostgreSQL $PGDUMP" 11 ebegin "Restoring PostgreSQL $PGDUMP"
14 psql -U ${PG_USER:-postgres} ${PSQL_OPTS} -f "$PGDUMP" >/dev/null 2>/dev/null 12 psql -U ${PG_USER:-postgres} ${PSQL_OPTS} -f "$PGDUMP" >/dev/null 2>/dev/null
13 local res=$?
15 yesno "$KEEP_DUMP" || rm -f "$PGDUMP" 14 yesno "$KEEP_DUMP" || rm -f "$PGDUMP"
16
17 su -l ${PGUSER} \
18 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload " >/dev/null
19 eend $res 15 eend $res
16 /etc/init.d/postgresql reload
20} 17}
21 18
22dump() { 19dump() {
diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd
index 0bf3350b63..7313984024 100644
--- a/main/postgresql/postgresql.confd
+++ b/main/postgresql/postgresql.confd
@@ -1,56 +1,51 @@
1# PostgreSQL's Database Directory 1# Which port and socket to bind PostgreSQL
2PGDATA="/var/lib/postgresql/9.1/data" 2PGPORT="5432"
3 3
4# PostgreSQL User 4# How long to wait for server to start in seconds
5PGUSER="postgres" 5START_TIMEOUT=10
6 6
7# PostgreSQL Group 7# NICE_QUIT ignores new connections and wait for clients to disconnect from
8PGGROUP="postgres" 8# server before shutting down. NICE_TIMEOUT in seconds determines how long to
9# wait for this to succeed.
10NICE_TIMEOUT=60
11
12# Forecfully disconnect clients from server and shut down. This is performed
13# after NICE_QUIT. Terminated client connections have their open transactions
14# rolled back.
15# Set RUDE_QUIT to "NO" to disable. RUDE_TIMEOUT in seconds.
16RUDE_QUIT="YES"
17RUDE_TIMEOUT=30
18
19# If the server still fails to shutdown, you can force it to quit by setting
20# this to YES and a recover-run will execute on the next startup.
21# Set FORCE_QUIT to "YES" to enable. FORCE_TIMEOUT in seconds.
22FORCE_QUIT="NO"
23FORCE_TIMEOUT=2
9 24
10# Extra options to run postmaster with, e.g.: 25# Extra options to run postmaster with, e.g.:
11# -N is the maximal number of client connections 26# -N is the maximal number of client connections
12# -B is the number of shared buffers and has to be at least 2x the value for -N 27# -B is the number of shared buffers and has to be at least 2x the value for -N
13# Please read the man-page to postmaster for more options. Many of these options 28# Please read the man-page to postmaster for more options. Many of these
14# can be set directly in the configuration-file. 29# options can be set directly in the configuration file.
15#PGOPTS="-N 512 -B 1024" 30#PGOPTS="-N 512 -B 1024"
16 31
32# Pass extra environment variables. If you have to export environment variables
33# for the database process, this can be done here.
34# Don't forget to escape quotes.
35#PG_EXTRA_ENV="PGPASSFILE=\"/path/to/.pgpass\""
17 36
18# SERVER SHUTDOWN: 37##############################################################################
19# The server will receive 3 signals in the worst case:
20# 1. SIGTERM
21# This signals the server to ignore new connections and to
22# wait for all clients to end their transactions before shutting down.
23# Use WAIT_FOR_DISCONNECT to control how much time the clients
24# should have until the next signal is being sent.
25# 2. SIGINT
26# Tell the server to forcefully disconnect all clients.
27# Terminating a client results in a rollback of the open transactions for this client.
28# Use WAIT_FOR_CLEANUP to determine how much time the server has
29# for cleanup.
30# 3. SIGQUIT
31# This will terminate the server immediately and results in a recovery run for the next start.
32
33# Wait for clients to disconnect
34WAIT_FOR_DISCONNECT=30
35
36# Time the server has to clean up
37WAIT_FOR_CLEANUP=60
38
39# Time the server has to quit (with a recover-run on next startup)
40# Set to 0 to deactivate it
41WAIT_FOR_QUIT=60
42
43# Comment this out if you don't want to wait for the server to
44# startup before continuing. For example, if this server is a
45# PITR log shipping based replication standby
46WAIT_FOR_START="-w"
47
48# If you have to export environment variables for the database process,
49# this can be done here.
50# 38#
51# Example: 39# The following values should not be arbitrarily changed.
52# export R_HOME="/usr/lib/R" 40#
41# The initscript uses these variables to inform PostgreSQL where to find
42# its data directory and configuration files.
43#
44##############################################################################
53 45
54# Automatically set up a new database if missing on startup 46# PostgreSQL's Database Directory
55AUTO_SETUP=yes 47PGDATA="/var/lib/postgresql/9.2/data"
56 48
49# Additional options to pass to initdb.
50# See `man initdb' for available options.
51#PG_INITDB_OPTS="--locale=en_US.UTF-8"
diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd
index 785826bd2f..6771c85045 100644
--- a/main/postgresql/postgresql.initd
+++ b/main/postgresql/postgresql.initd
@@ -12,10 +12,25 @@ depend() {
12 after firewall 12 after firewall
13} 13}
14 14
15get_config() {
16 [ -f ${PGDATA%/}/postgresql.conf ] || return 1
17 eval echo $(sed -e 's:#.*::' ${PGDATA%/}/postgresql.conf | awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
18}
19
20
15checkconfig() { 21checkconfig() {
16 [ -d "$PGDATA/base" ] && return 0 22 configured_port=$(get_config port)
17 echo "checking config" 23 : ${configured_port:=${PGPORT:-5432}}
24 socket_path=$(get_config unix_socket_directory)
25 : ${socket_path:=/var/run/postgresql}
18 26
27 checkpath -d -m 0770 -o postgres:postgres ${socket_path}
28
29 if [ -n "$WAIT_FOR_START" ]; then
30 START_TIMEOUT=$WAIT_FOR_START
31 fi
32
33 [ -d "$PGDATA/base" ] && return 0
19 if [ -z "$AUTO_SETUP" ] ; then 34 if [ -z "$AUTO_SETUP" ] ; then
20 eerror "Database not found at: $PGDATA" 35 eerror "Database not found at: $PGDATA"
21 eerror "Please make sure that PGDATA points to the right path." 36 eerror "Please make sure that PGDATA points to the right path."
@@ -34,72 +49,71 @@ start() {
34 rm -f "$PGDATA/postmaster.pid" 49 rm -f "$PGDATA/postmaster.pid"
35 fi 50 fi
36 51
37 local retval 52 local retval= x= extraenv=
38 53 for x in ${PG_EXTRA_ENV} ; do
39 su -l ${PGUSER} \ 54 extraenv="${extraenv} --env ${x}"
40 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl start ${WAIT_FOR_START} -o '--silent-mode=true ${PGOPTS}'" >/dev/null 55 done
56
57 start-stop-daemon --start \
58 --user ${PGUSER:-postgres} \
59 --group ${PGGROUP:-postgres} \
60 --env "PGPORT=${configured_port}" \
61 ${extraenv} \
62 --pidfile ${PGDATA}/postmaster.pid \
63 --wait 100 \
64 --exec /usr/bin/pg_ctl \
65 -- \
66 start -s -w -t ${START_TIMEOUT:-10} \
67 -l ${PGDATA}/postmaster.log \
68 -D ${PGDATA} -o "--data-directory=${PGDATA} $PGOPTS"
41 retval=$? 69 retval=$?
42 [ $retval -ne 0 ] && eend $retval && return $retval
43
44 # The following is to catch the case of an already running server
45 # in which pg_ctl doesn't know to which server it connected to and false reports the server as 'up'
46 sleep 2
47 if [ ! -f "$PGDATA/postmaster.pid" ] ; then
48 eerror "The pid-file doesn't exist but pg_ctl reported a running server."
49 eerror "Please check whether there is another server running on the same port or read the log-file."
50 eend 1
51 return 1
52 fi
53 70
54 local pid 71 if [ $retval -ne 0 ] ; then
55 read pid < "$PGDATA/postmaster.pid" 72 eerror "Check the log for a possible explanation of the above error."
56 test -d /proc/"${pid}" 73 eerror " ${PGDATA}/postmaster.log"
57 eend $? 74 fi
75 eend $retval
58} 76}
59 77
60stop() { 78stop() {
61 ebegin "Stopping PostgreSQL (this can take up to $(( ${WAIT_FOR_DISCONNECT} + ${WAIT_FOR_CLEANUP} )) seconds)" 79 if [ -n "$WAIT_FOR_DISCONNECT" ]; then
80 NICE_TIMEOUT=$WAIT_FOR_DISCONNECT
81 fi
82 if [ -n "$WAIT_FOR_CLEANUP" ]; then
83 RUDE_QUIT=YES
84 RUDE_TIMEOUT=$WAIT_FOR_CLEANUP
85 fi
86 if [ -n "$WAIT_FOR_QUIT" ] && [ $WAIT_FOR_QUIT -ne 0 ]; then
87 FORCE_QUIT=YES
88 FORCE_TIMEOUT=$WAIT_FOR_QUIT
89 fi
62 90
91 local seconds=${NICE_TIMEOUT}
63 local retval 92 local retval
64 93 local retries=SIGTERM/${NICE_TIMEOUT}
65 su -l ${PGUSER} \ 94 if [ "${RUDE_QUIT}" != "NO" ] ; then
66 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -t ${WAIT_FOR_DISCONNECT} -m smart" >/dev/null 95 retries="${retries}/SIGINT/${RUDE_TIMEOUT}"
67 96 seconds=$(( $seconds + ${NICE_TIMEOUT} ))
68 retval=$? 97 fi
69 [ $retval -eq 0 ] && eend $retval && return $retval 98 if [ "${FORCE_QUIT}" = "YES" ] ; then
70 99 retries="${retries}/SIGQUIT/${FORCE_TIMEOUT}"
71 ewarn "Some clients did not disconnect within ${WAIT_FOR_DISCONNECT} seconds." 100 seconds=$(( $seconds + ${FORCE_TIMEOUT} ))
72 ewarn "Going to shutdown the server anyway."
73
74 su -l ${PGUSER} \
75 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -m fast" >/dev/null
76
77 retval=$?
78 [ $retval -eq 0 ] && eend $retval && return $retval
79
80 if [ ${WAIT_FOR_QUIT} -eq 0 ] ; then
81 eerror "Server did not shut down and sending the SIGQUIT has been disabled."
82 eend $retval
83 return $retval
84 fi 101 fi
85 102
86 ewarn "Shutting down the server gracefully failed." 103 ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)"
87 ewarn "Forcing it to shutdown which leads to a recover-run on next startup."
88
89 su -l ${PGUSER} \
90 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -m immediate" >/dev/null
91
92 retval=$?
93 [ $retval -eq 0 ] && eend $retval && return $retval
94 104
95 eerror "Forced shutdown failed!!! Something is wrong with your system, please take care of it manually." 105 # Loops through nice, rude, and force quit in one go.
96 eend $? 106 start-stop-daemon --stop \
107 --exec /usr/bin/postgres \
108 --retry ${retries} \
109 --progress \
110 --pidfile ${PGDATA}/postmaster.pid
111 eend
97} 112}
98 113
99reload() { 114reload() {
100 ebegin "Reloading PostgreSQL configuration" 115 ebegin "Reloading PostgreSQL configuration"
101 su -l ${PGUSER} \ 116 kill -HUP $(head -n1 ${PGDATA}/postmaster.pid)
102 -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload" >/dev/null
103 eend $? 117 eend $?
104} 118}
105 119
@@ -124,8 +138,6 @@ setup() {
124 chmod 0700 "${PGDATA}" 138 chmod 0700 "${PGDATA}"
125 cd "${PGDATA}" # to avoid the: could not change directory to "/root" 139 cd "${PGDATA}" # to avoid the: could not change directory to "/root"
126 su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres 140 su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres
127 einfo "You can use the '/etc/init.d/postgresql' script to run PostgreSQL instead"
128 einfo "of 'pg_ctl'."
129 local res=$? 141 local res=$?
130 142
131 # move the pg_hba.conf and friends 143 # move the pg_hba.conf and friends