4 path: /var/lib/postgresql/take-database-backup
5 chown: postgres:postgres
10 FILENAME=/shared/postgres_backup/$ID.tar.gz
11 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
15 path: /var/spool/cron/crontabs/postgres
17 # m h dom mon dow command
19 0 */4 * * * /var/lib/postgresql/take-database-backup
23 filename: /etc/service/unicorn/run
25 to: sv start postgres || exit 1
29 - exec: apt-get install -y socat
30 - exec: mkdir -p /shared/postgres_run
31 - exec: chown postgres:postgres /shared/postgres_run
32 - exec: chmod 775 /shared/postgres_run
33 - exec: rm -fr /var/run/postgresql
34 - exec: ln -s /shared/postgres_run /var/run/postgresql
35 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
37 path: /etc/service/postgres/run
42 exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main
46 - chown -R root /var/lib/postgresql/9.2/main
47 - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -u postgres /usr/lib/postgresql/9.2/bin/initdb -D /shared/postgres_data || exit 0"
48 - chown -R postgres:postgres /shared/postgres_data
51 filename: "/etc/postgresql/9.2/main/postgresql.conf"
52 from: "data_directory = '/var/lib/postgresql/9.2/main'"
53 to: "data_directory = '/shared/postgres_data'"
55 # listen on all interfaces
57 filename: "/etc/postgresql/9.2/main/postgresql.conf"
58 from: /#?listen_addresses *=.*/
59 to: "listen_addresses = '*'"
61 # Necessary to enable backups
64 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
67 filename: "/etc/postgresql/9.2/main/postgresql.conf"
68 from: /#?max_wal_senders *=.*/
69 to: "max_wal_senders = 4"
72 filename: "/etc/postgresql/9.2/main/postgresql.conf"
73 from: /#?wal_level *=.*/
74 to: "wal_level = hot_standby"
77 filename: "/etc/postgresql/9.2/main/pg_hba.conf"
78 from: /^#local +replication +postgres +peer$/
79 to: "local replication postgres peer"
81 # allow all to connect in with md5 auth
83 filename: "/etc/postgresql/9.2/main/pg_hba.conf"
84 from: /^host.*all.*all.*127.*$/
85 to: "host all all 0.0.0.0/0 md5"
89 cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"
91 # give db a few secs to start up
94 - exec: sudo -u postgres createdb discourse || exit 0
97 create user discourse;
98 cmd: sudo -u postgres psql discourse
103 grant all privileges on database discourse to discourse;
104 cmd: sudo -u postgres psql discourse
107 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "alter schema public owner to discourse;"'
108 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"'
109 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"'
113 cmd: "echo postgres installed!"