aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-04-15 22:41:06 +0200
committerJakub Jirutka <jakub@jirutka.cz>2017-04-15 23:37:29 +0200
commitf8d6bc22ed6fec13b4fe4ec4f2cd8349d2299e0d (patch)
tree2b645347c80c0c1735fbb5d49706b918f9858186
parent10d9cc8000c7da49bf13e516928f30fc80b1cf9f (diff)
downloadaports-f8d6bc22ed6fec13b4fe4ec4f2cd8349d2299e0d.tar.bz2
aports-f8d6bc22ed6fec13b4fe4ec4f2cd8349d2299e0d.tar.xz
main/postgresql: split data and configs
Configuration files belong to /etc, not /var/lib/. This change is inspired by Gentoo package. This change will NOT affect existing users, until they update their /etc/conf.d/postgresql config to the new format without changing conf_dir.
-rw-r--r--main/postgresql/APKBUILD4
-rw-r--r--main/postgresql/postgresql.confd7
-rw-r--r--main/postgresql/postgresql.initd55
3 files changed, 42 insertions, 24 deletions
diff --git a/main/postgresql/APKBUILD b/main/postgresql/APKBUILD
index cdda829fa7..76f9e96906 100644
--- a/main/postgresql/APKBUILD
+++ b/main/postgresql/APKBUILD
@@ -240,8 +240,8 @@ _submv() {
sha512sums="7c9d61a591408e29d7dc70d6b28ecdf06edf7f8fbf4e014e60a1e4f841fd5734c74a820094f6153e10ef633d48ea73f2a85194f6d2cd519a8f7087a261e9e02b postgresql-9.6.2.tar.bz2
0b88eee78380ed6cf543c851ac1cea5fc50bb6ef1bb51e03694003f43d2bf4e117ff06657f958d0e9c00ace3b8a6bab6ed0bd017d23f80cfd203dab33da81d46 initdb.patch
5f9d8bb4957194069d01af8ab3abc6d4d83a7e7f8bd7ebe1caae5361d621a3e58f91b14b952958138a794e0a80bc154fbb7e3e78d211e2a95b9b7901335de854 perl-rpath.patch
-73807f0d6ddc239c0fc2308164cf3e6ef361f98553ec24408afc4aeb1db9aea24746caf57e2cd1405eddaac4f26e9a55bf5aa1abcf08cd9ce3e9818754d4746a postgresql.initd
-34912a2f9c5f660055cdf182f023981bf23f1995c2ba7b1172007dd90df9684952964ce574cfd86d6854bd6d057fd9dda67d6055dd765a65d03c1eaf5b33d22e postgresql.confd
+224e80f9e62843fd248e625abdd0d9fe477729ff3f9a64fc5c86dd37bb7176d3504107fbed7ce578e3a1db7f60b8cf2abf5fe4862c81f76b6d026e29ca495cfc postgresql.initd
+0eecc038e5b01995771c7c4403aa76a5077c54b9a8bd5c03e51fa580fc772792c0ae0b84b0845b949a46b77e4f19f0e37351a4af429ecb629a4480035b9871f6 postgresql.confd
f5a1cba051e7d846c2d16703514601cb25729ed96b677c9bd0c199d64552120a8b14b238af01917fdb87106681e12dee6fff7447558155ba273e4f96be5e2892 pg-restore.initd
c14a5684e914abb3b0ee71bbf15eed71a9264deacaa404a6e3af6bfc330d93e7598624d0ed11a94263106cc660f7f54c8ff57e759033cf606a795f69ff6c1c7c pg-restore.confd
5c9bfd9e295dcf678298bf0aa974347a7c311d6e7c2aa76a6920fcb751d01fd1ab77abbec11f3c672f927ad9deaa88e04e370c0b5cd1b60087554c474b748731 pltcl_create_tables.sql"
diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd
index b5b57329a9..fc7a1c7888 100644
--- a/main/postgresql/postgresql.confd
+++ b/main/postgresql/postgresql.confd
@@ -45,8 +45,11 @@
# The initscript uses these variables to inform PostgreSQL where to find
# its data directory and configuration files.
-# PostgreSQL's Database Directory
-#PGDATA="/var/lib/postgresql/@VERSION@/data"
+# Where the data directory is located/to be created.
+#data_dir="/var/lib/postgresql/@VERSION@/data"
+
+# Location of configuration files. Default is $data_dir.
+conf_dir="/etc/postgresql"
# Additional options to pass to initdb.
# See man initdb(1) for available options.
diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd
index 63b4f0c522..846229a40c 100644
--- a/main/postgresql/postgresql.initd
+++ b/main/postgresql/postgresql.initd
@@ -19,17 +19,18 @@ description_setup="Initialize a new PostgreSQL cluster"
: ${force_quit:=${FORCE_QUIT:-"no"}}
: ${force_timeout:=${FORCE_TIMEOUT:-2}}
+: ${data_dir:=${PGDATA:-"/var/lib/postgresql/@VERSION@/data"}}
+: ${conf_dir:=$data_dir}
: ${env_vars:=${PG_EXTRA_ENV:-}}
: ${initdb_opts:=${PG_INITDB_OPTS:-}}
-: ${logfile:="$PGDATA/postmaster.log"}
+: ${logfile:="$data_dir/postmaster.log"}
: ${pg_opts:=${PGOPTS:-}}
: ${port:=${PGPORT:-5432}}
-: ${PGDATA:="/var/lib/postgresql/@VERSION@/data"}
command="/usr/bin/postgres"
-conffile="$PGDATA/postgresql.conf"
-pidfile="$PGDATA/postmaster.pid"
+conffile="$conf_dir/postgresql.conf"
+pidfile="$data_dir/postmaster.pid"
start_stop_daemon_args="
--user $user
--group $group
@@ -51,12 +52,12 @@ start_pre() {
check_deprecated_var WAIT_FOR_CLEANUP rude_timeout
check_deprecated_var WAIT_FOR_QUIT force_timeout
- if [ ! -d "$PGDATA/base" ]; then
+ if [ ! -d "$data_dir/base" ]; then
if yesno "$auto_setup"; then
setup || return 1
else
- eerror "Database not found at: $PGDATA"
- eerror "Please make sure that PGDATA points to the right path."
+ eerror "Database not found at: $data_dir"
+ eerror "Please make sure that 'data_dir' points to the right path."
eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster."
return 1
fi
@@ -101,8 +102,8 @@ start() {
--silent \
-w --timeout="$start_timeout" \
--log="$logfile" \
- --pgdata="$PGDATA" \
- -o "$pg_opts"
+ --pgdata="$conf_dir" \
+ -o "--data-directory=$data_dir $pg_opts"
retval=$?
if [ $retval -ne 0 ]; then
@@ -147,29 +148,43 @@ setup() {
ebegin "Creating a new PostgreSQL database cluster"
- if [ -d "$PGDATA/base" ]; then
- eend 1 "$PGDATA/base already exists!"; return 1
+ if [ -d "$data_dir/base" ]; then
+ eend 1 "$data_dir/base already exists!"; return 1
fi
- # If the pg_hba.conf and friends exist, backup them.
- if [ -d "$PGDATA" ]; then
+ # If data_dir exists, backup configs.
+ if [ -d "$data_dir" ]; then
bkpdir="$(mktemp -d)"
- mv "$PGDATA"/* "$bkpdir"/
- rm -rf "$PGDATA"/*
+ find "$data_dir" -type f -name "*.conf" -maxdepth 1 \
+ -exec mv -v {} "$bkpdir"/ \;
+ rm -rf "$data_dir"/*
fi
- install -d -m 0700 -o $user -g $group "$PGDATA"
+ install -d -m 0700 -o $user -g $group "$data_dir"
+ install -d -m 0750 -o $user -g $group "$conf_dir"
- cd "$PGDATA" # to avoid the: could not change directory to "/root"
- su $user -c "/usr/bin/initdb $initdb_opts --pgdata $PGDATA"
+ cd "$data_dir" # to avoid the: could not change directory to "/root"
+ su $user -c "/usr/bin/initdb $initdb_opts --pgdata $data_dir"
local retval=$?
if [ -d "$bkpdir" ]; then
- # Move the pg_hba.conf and friends back.
- mv "$bkpdir"/* "$PGDATA"/ 2>/dev/null
+ # Move backuped configs back.
+ mv -v "$bkpdir"/* "$data_dir"/
rm -rf "$bkpdir"
fi
+ if [ "${data_dir%/}" != "${conf_dir%/}" ]; then
+ # Move configs from data_dir to conf_dir and symlink them to data_dir.
+ local name newname
+ for name in postgresql.conf pg_hba.conf pg_ident.conf; do
+ newname="$name"
+ [ ! -e "$conf_dir"/$name ] || newname="$name.new"
+
+ mv "$data_dir"/$name "$conf_dir"/$newname
+ ln -s "$conf_dir"/$name "$data_dir"/$name
+ done
+ fi
+
eend $retval
}