Skip to content

Commit

Permalink
Update postgresql to 9.6.6 and enable it to run without pkg_svc_user=…
Browse files Browse the repository at this point in the history
…root

Signed-off-by: Irving Popovetsky <[email protected]>
  • Loading branch information
Irving Popovetsky committed Nov 17, 2017
1 parent b59be5c commit 538edc7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
8 changes: 3 additions & 5 deletions postgresql/config/functions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
init_pgpass() {
export PGPASSFILE="{{pkg.svc_config_path}}/.pgpass"
chmod 0600 {{pkg.svc_config_path}}/.pgpass
}

write_local_conf() {
Expand Down Expand Up @@ -59,13 +58,12 @@ master_ready() {
bootstrap_replica_via_pg_basebackup() {
echo 'Bootstrapping replica via pg_basebackup from leader '

rm -rf {{pkg.svc_data_path}}/*
pg_basebackup --pgdata={{pkg.svc_data_path}} --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres'
rm -rf {{cfg.data_directory}}/*
pg_basebackup --pgdata={{cfg.data_directory}} --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres'
}

ensure_dir_ownership() {
echo 'Making sure hab user owns var, config and data paths'
echo 'Making sure hab user owns var and data paths'
chown -RL hab:hab {{pkg.svc_var_path}}
chown -RL hab:hab {{pkg.svc_config_path}}
chown -RL hab:hab {{pkg.svc_data_path}}
}
2 changes: 1 addition & 1 deletion postgresql/config/postgresql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ datestyle = 'iso, mdy'

default_text_search_config = 'pg_catalog.english'

data_directory = '{{pkg.svc_data_path}}'
data_directory = '{{cfg.data_directory}}'
hba_file = '{{pkg.svc_config_path}}/pg_hba.conf'

wal_level = hot_standby
Expand Down
3 changes: 2 additions & 1 deletion postgresql/default.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
port = 5432

data_directory = "/hab/svc/postgresql/data/pgdata"
max_connections = 100
max_locks_per_transaction = 64
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h %r (%x:%e)'
Expand All @@ -15,4 +16,4 @@ name = 'replication'
password = 'replication'
lag_health_threshold = 1048576
enable = false
archive_path = "{{pkg.svc_path}}/archive"
archive_path = "hab/svc/postgresql/data/archive"
8 changes: 4 additions & 4 deletions postgresql/hooks/init
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ source {{pkg.svc_config_path}}/functions.sh

mkdir -p {{pkg.svc_config_path}}/conf.d
mkdir -p {{pkg.svc_var_path}}/pg_stat_tmp
mkdir -p {{pkg.svc_path}}/archive
mkdir -p {{cfg.data_directory}}
mkdir -p {{cfg.replication.archive_path}}

init_pgpass
ensure_dir_ownership

{{#unless svc.me.follower ~}}
if [[ ! -f "{{pkg.svc_data_path}}/PG_VERSION" ]]; then
if [[ ! -f "{{cfg.data_directory}}/PG_VERSION" ]]; then
echo " Database does not exist, creating with 'initdb'"
chpst -U hab:hab -u hab:hab \
initdb -U {{cfg.superuser.name}} \
-E utf8 \
-D {{pkg.svc_data_path}} \
-D {{cfg.data_directory}} \
--pwfile {{pkg.svc_config_path}}/pwfile \
--locale POSIX \
--data-checksums
Expand Down
4 changes: 2 additions & 2 deletions postgresql/hooks/reconfigure
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ source {{pkg.svc_config_path}}/functions.sh
init_pgpass

{{ #unless svc.me.follower }}
if [ -f {{pkg.svc_data_path}}/recovery.conf ]; then
if [ -f {{cfg.data_directory}}/recovery.conf ]; then
echo "Promoting database"
until pg_isready -U {{cfg.superuser.name}} -h localhost -p {{cfg.port}}; do
echo "Waiting for database to start"
sleep 1
done

chpst -U hab:hab -u hab:hab pg_ctl promote -D {{pkg.svc_data_path}}
pg_ctl promote -D {{cfg.data_directory}}
fi

{{~/unless}}
8 changes: 4 additions & 4 deletions postgresql/hooks/run
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ init_pgpass
write_local_conf

{{#if svc.me.follower }}
if [[ ! -f "{{pkg.svc_data_path}}/PG_VERSION" ]]; then
if [[ ! -f "{{cfg.data_directory}}/PG_VERSION" ]]; then
bootstrap_replica_via_pg_basebackup
fi

cp {{pkg.svc_config_path}}/recovery.conf {{pkg.svc_data_path}}/
cp {{pkg.svc_config_path}}/recovery.conf {{cfg.data_directory}}/recovery.conf
{{/if}}

ensure_dir_ownership

echo "Starting PostgreSQL"
export PGDATA={{pkg.svc_data_path}}
exec chpst -U hab:hab -u hab:hab postgres \
export PGDATA={{cfg.data_directory}}
exec postgres \
-c config_file={{pkg.svc_config_path}}/postgresql.conf
11 changes: 4 additions & 7 deletions postgresql/plan.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pkg_name=postgresql
pkg_version=9.6.3
pkg_version=9.6.6
pkg_origin=core
pkg_maintainer="The Habitat Maintainers <[email protected]>"
pkg_description="PostgreSQL is a powerful, open source object-relational database system."
pkg_upstream_url="https://www.postgresql.org/"
pkg_license=('PostgreSQL')
pkg_source=https://ftp.postgresql.org/pub/source/v${pkg_version}/${pkg_name}-${pkg_version}.tar.bz2
pkg_shasum=1645b3736901f6d854e695a937389e68ff2066ce0cde9d73919d6ab7c995b9c6
pkg_shasum=399cdffcb872f785ba67e25d275463d74521566318cfef8fe219050d063c8154

pkg_deps=(
core/bash
Expand Down Expand Up @@ -44,13 +44,10 @@ pkg_exports=(
)
pkg_exposes=(port)

pkg_svc_user=root
pkg_svc_group=$pkg_svc_user

ext_postgis_version=2.3.2
ext_postgis_version=2.4.2
ext_postgis_source=http://download.osgeo.org/postgis/source/postgis-${ext_postgis_version}.tar.gz
ext_postgis_filename=postgis-${ext_postgis_version}.tar.gz
ext_postgis_shasum=e92e34c18f078a3d1a2503cd870efdc4fa9e134f0bcedbbbdb8b46b0e6af09e4
ext_postgis_shasum=23625bc99ed440d53a20225721095a3f5c653b62421c4d597c8038f0d7a321d9

do_before() {
ext_postgis_dirname="postgis-${ext_postgis_version}"
Expand Down

0 comments on commit 538edc7

Please sign in to comment.