From 6a0aa89e3dfd7bd0755b67931532eaa173f73919 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sat, 14 Sep 2019 15:59:40 -0400 Subject: Initial --- defaults/main.yml | 1 + readme.md | 5 +++++ tasks/main.yml | 28 ++++++++++++++++++++++++++++ templates/run.j2 | 15 +++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 defaults/main.yml create mode 100644 readme.md create mode 100644 tasks/main.yml create mode 100644 templates/run.j2 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1 @@ + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c33eb97 --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +# Install Postgres and Runit service on Alpine Linux + +Ideally used in conjunction with my Alpine Linux +playbook, though it shouldn't be hard to adapt it to +other systems. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..7b67816 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,28 @@ +- name: Install Postgres + apk: + name: postgresql + update_cache: yes +- name: Install Runit service directory + file: + state: directory + path: /etc/sv/postgres + mode: '0755' +- name: Install Runit service command + template: + src: run.j2 + dest: /etc/sv/postgres/run + mode: '755' +- name: Install supervise symlink + file: + state: link + force: yes + src: /run/supervise.postgres + dest: /etc/sv/postgres/supervise + follow: false +- name: Enable postgres service + file: + state: link + force: yes + src: /etc/sv/postgres + dest: /var/service/postgres + follow: false diff --git a/templates/run.j2 b/templates/run.j2 new file mode 100644 index 0000000..9242dd2 --- /dev/null +++ b/templates/run.j2 @@ -0,0 +1,15 @@ +#!/bin/sh +set -e +pguser="postgres" +PGDATA="/var/postgres" + +if ! [ -d "$PGDATA" ] ; then + mkdir -p "$PGDATA" + chown -R "$pguser" "$PGDATA" + chmod 700 "$PGDATA" + su - postgres -m -c "pg_ctl initdb -D \"$PGDATA\"" +fi + +mkdir -p /run/postgresql && chown "$pguser" /run/postgresql +exec chpst -u postgres:postgres postgres -D "$PGDATA" 2>&1 + -- cgit v1.2.3