Skip to content

Commit a6c3667

Browse files
dragomirprenovate[bot]taurus-forever
authored
[DPE-6854] Stablisation polish - PG 14 (#16)
* [DPE-6749] Postgresql 16 (#4) * Postgresql 16 * Switch to platforms * Refs to pg14 * Missing perl * [MISC] Update PG version and dual branch configuration (#6) * Dual branch configuration * PG version bump * Remove unneeded tox config (#8) * Lock file maintenance Python dependencies (#14) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update canonical/data-platform-workflows action to v31 (#13) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Remove prefixes * Move config to SNAP_DATA * Twea install * Fake clustering * Cluster script * Use postgresql-common * Override PG user * Less restrictive wrappers * Create cluster filtering * Apply suggestions from code review Co-authored-by: Alex Lutay <[email protected]> * Fix root check * Make pg_ctlcluster accessible to rename and drop cluster * Startup checks * Remove sytemd errors when dropping or renaming a cluster * Set priv wrapper for ctl and conftool * Tweaks --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Alex Lutay <[email protected]>
1 parent a62ed69 commit a6c3667

File tree

12 files changed

+286
-86
lines changed

12 files changed

+286
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.snap

snap/hooks/install

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#!/bin/bash
22

3-
mkdir -p $SNAP_DATA/etc/postgresql
3+
mkdir -p "$SNAP_COMMON/etc/postgresql/"
4+
cp -r "$SNAP/default-config/etc/postgresql-common" "$SNAP_COMMON/etc"
45

5-
mkdir -p $SNAP_COMMON/pgsql/
6-
mkdir -p $SNAP_COMMON/pgsql/data
7-
mkdir -p $SNAP_COMMON/postgresql.failed
8-
mkdir -p $SNAP_COMMON/data/db
6+
mkdir -p "$SNAP_COMMON/var/lib/postgresql"
7+
mkdir -p "$SNAP_COMMON/var/log/postgresql"
98

10-
mkdir -p $SNAP_COMMON/var/lib/postgresql
11-
mkdir -p $SNAP_COMMON/var/log/postgresql
9+
chown -R 584792:root "$SNAP_COMMON"/*
10+
chown -R 584792:root "$SNAP_DATA"/*
1211

13-
chown -R 584788:root $SNAP_COMMON/*
14-
chown -R 584788:root $SNAP_DATA/*
12+
PG_MAJOR_VER=$(echo "$SNAP_VERSION" | cut -d "." -f 1)
1513

16-
export LOCPATH="${SNAP}"/usr/lib/locale
17-
export PGDATA=$SNAP_COMMON/pgsql/data
18-
19-
"${SNAP}/usr/bin/setpriv" --clear-groups --reuid snap_daemon --regid snap_daemon -- "${SNAP}/usr/lib/postgresql/14/bin/initdb" -U postgres -D "${PGDATA}"
14+
"$SNAP/create-cluster.sh" "$PG_MAJOR_VER" main

snap/local/archivecleanup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "${EUID}" != "0" ]; then
5+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
6+
exit 1
7+
fi
8+
9+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_archivecleanup "$@"

snap/local/conftool.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
if [ "${EUID}" != "0" ]; then
4+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
5+
exit 1
6+
fi
7+
8+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_conftool "$@"

snap/local/create-cluster.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "${EUID}" != "0" ]; then
5+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
6+
exit 1
7+
fi
8+
9+
# Filter out unwanted args
10+
CLUSTER_ARGS=()
11+
INITDB_ARGS=()
12+
SKIP_NEXT=0
13+
14+
while [[ $# -gt 0 ]]; do
15+
if (( SKIP_NEXT )); then
16+
SKIP_NEXT=0
17+
shift
18+
continue
19+
fi
20+
21+
case "$1" in
22+
-u)
23+
echo "WARNING: User must be _daemon_! Skipping"
24+
SKIP_NEXT=1
25+
;;
26+
-g)
27+
echo "WARNING: Group must be root! Skipping"
28+
SKIP_NEXT=1
29+
;;
30+
-s)
31+
echo "WARNING: Socket dir must be default! Skipping"
32+
SKIP_NEXT=1
33+
;;
34+
-d)
35+
echo "WARNING: Data dir must be default! Skipping"
36+
SKIP_NEXT=1
37+
;;
38+
-l)
39+
echo "WARNING: Logfile must be default! Skipping"
40+
SKIP_NEXT=1
41+
;;
42+
--start)
43+
echo "WARNING: New cluster cannot be started! Skipping"
44+
;;
45+
--start-conf)
46+
echo "WARNING: Start conf must be manual! Skipping"
47+
SKIP_NEXT=1
48+
;;
49+
--)
50+
shift
51+
INITDB_ARGS=("$@")
52+
break
53+
;;
54+
*)
55+
CLUSTER_ARGS+=("$1")
56+
;;
57+
esac
58+
shift
59+
done
60+
61+
PG_MAJOR_VER=$(echo "$SNAP_VERSION" | cut -d "." -f 1)
62+
NAME="${CLUSTER_ARGS[-1]}"
63+
64+
if [ "$PG_MAJOR_VER" != "${CLUSTER_ARGS[-2]}" ]
65+
then echo "Cannot create ${CLUSTER_ARGS[-2]} cluster on $PG_MAJOR_VER snap."
66+
exit
67+
fi
68+
69+
# Check for necessary initdb args
70+
for ((i=0; i<"${#INITDB_ARGS[@]}"; ++i)); do
71+
case ${INITDB_ARGS[i]} in
72+
-U | --username | --username=*) PG_USER=true;;
73+
--auth-host | --auth-host=*) HOST_AUTH=true;;
74+
--auth-local | --auth-local=*) LOCAL_AUTH=true;;
75+
-A | --auth | --auth=*) HOST_AUTH=true; LOCAL_AUTH=true;;
76+
esac
77+
done
78+
79+
if [ -z "$PG_USER" ]; then
80+
INITDB_ARGS+=('-U')
81+
INITDB_ARGS+=('postgres')
82+
fi
83+
84+
if [ -z "$LOCAL_AUTH" ]; then
85+
INITDB_ARGS+=('--auth-local=trust')
86+
fi
87+
88+
if [ -z "$HOST_AUTH" ]; then
89+
INITDB_ARGS+=('--auth-host=scram-sha-256')
90+
fi
91+
92+
93+
# TODO figure out local-auth
94+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_createcluster -u _daemon_ -g root --start-conf=manual "${CLUSTER_ARGS[@]}" -- "${INITDB_ARGS[@]}"
95+
96+
# Inject LD_LIBRARY_PATH in the env file
97+
echo "LD_LIBRARY_PATH='$LD_LIBRARY_PATH'" | sed "s#/$SNAP_REVISION/#/current/#g" | "$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- tee -a "$SNAP_COMMON/etc/postgresql/$PG_MAJOR_VER/$NAME/environment"
98+
99+
echo "The cluster can be started with: 'postgresql.ctlcluster --skip-systemctl-redirect $PG_MAJOR_VER $NAME start'"

snap/local/ctl-cluster.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
if [ "${EUID}" != "0" ]; then
4+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
5+
exit 1
6+
fi
7+
8+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_ctlcluster "$@"

snap/local/ctl.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
if [ "${EUID}" != "0" ]; then
4+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
5+
exit 1
6+
fi
7+
8+
PG_MAJOR_VER=$(echo "$SNAP_VERSION" | cut -d "." -f 1)
9+
10+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- "$SNAP/usr/lib/postgresql/$PG_MAJOR_VER/bin/pg_ctl" "$@"

snap/local/drop-cluster.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "${EUID}" != "0" ]; then
5+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
6+
exit 1
7+
fi
8+
9+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_dropcluster "$@"

snap/local/rename-cluster.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "${EUID}" != "0" ]; then
5+
echo "Error: run it as root (to utilize snap user _daemon_)." >&2
6+
exit 1
7+
fi
8+
9+
"$SNAP/usr/bin/setpriv" --clear-groups --reuid _daemon_ --regid root -- pg_renamecluster "$@"

snap/local/start-postgresql.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)