diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2017-04-15 22:41:06 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-04-15 23:37:29 +0200 |
commit | f8d6bc22ed6fec13b4fe4ec4f2cd8349d2299e0d (patch) | |
tree | 2b645347c80c0c1735fbb5d49706b918f9858186 /main/postgresql/postgresql.initd | |
parent | 10d9cc8000c7da49bf13e516928f30fc80b1cf9f (diff) | |
download | aports-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.
Diffstat (limited to 'main/postgresql/postgresql.initd')
-rw-r--r-- | main/postgresql/postgresql.initd | 55 |
1 files changed, 35 insertions, 20 deletions
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 } |