From 5694eeff43c56385a454caba66d7e7c28acb5e8d Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 17 Oct 2021 17:32:16 +1100 Subject: [PATCH] [WIP] Add postgresql service. --- usr/share/66/service/postgresql | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 usr/share/66/service/postgresql diff --git a/usr/share/66/service/postgresql b/usr/share/66/service/postgresql new file mode 100644 index 00000000..e9266c5f --- /dev/null +++ b/usr/share/66/service/postgresql @@ -0,0 +1,40 @@ +[main] +@type = classic +@version = 0.0.1 +@description = "PostgreSQL daemon" +@user = ( root ) + +[start] +@build = custom +@shebang = "/bin/sh" +@execute = ( + +. /etc/default/postgresql +: ${PGDATA:="$PGROOT/data"} + +if [ "$PGROOT" != "/var/lib/postgresql" ]; then + echo "Creating symlink /var/lib/postgresql -> $PGROOT" + + # Remove /var/lib/postgres if empty dir, but not if symlink + if [ ! -L /var/lib/postgres ] && [ -d /var/lib/postgres ]; then + rmdir /var/lib/postgres + fi + + ln -sf "$PGROOT" /var/lib/postgresql +fi + + +if [ ! -d "$PGDATA" ]; then + echo "Initializing database in $PGDATA" + + execl-toc -X -d "$PGDATA" -u postgres -g postgres -m 0700 + su - postgres -m -c "/usr/bin/initdb $INITOPTS -D '$PGDATA'" >/dev/null + + if [ -f /etc/postgresql/postgresql.conf ]; then + ln -sf /etc/postgresql/postgresql.conf "$PGDATA/postgresql.conf" + fi +fi + +exec s6-setuidgid postgres:postgres postgres -D "$PGDATA" $PGOPTS 2>&1 + +)