improve template
[discourse_docker.git] / templates / postgres.9.3.template.yml
1 hooks:
2 before_code:
3 - replace:
4 filename: /etc/service/unicorn/run
5 from: "# postgres"
6 to: sv start postgres || exit 1
7
8 run:
9 - exec: apt-get update && apt-get install -y postgresql-9.3
10 - exec: /etc/init.d/postgresql stop
11 - exec: mkdir -p /shared/postgres_run
12 - exec: chown postgres:postgres /shared/postgres_run
13 - exec: chmod 775 /shared/postgres_run
14 - exec: rm -fr /var/run/postgresql
15 - exec: ln -s /shared/postgres_run /var/run/postgresql
16 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
17 - exec: rm -fr /shared/postgres_run/.s*
18 - exec: rm -fr /shared/postgres_run/*.pid
19 - exec: mkdir -p /shared/postgres_run/9.3-main.pg_stat_tmp
20 - exec: chown postgres:postgres /shared/postgres_run/9.3-main.pg_stat_tmp
21 - file:
22 path: /etc/service/postgres/run
23 chmod: "+x"
24 contents: |
25 #!/bin/sh
26 exec 2>&1
27 echo -1000 >/proc/self/oom_score_adj
28 HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main
29
30 - file:
31 path: /etc/runit/3.d/99-postgres
32 chmod: "+x"
33 contents: |
34 #!/bin/bash
35 sv stop postgres
36
37 - exec:
38 cmd:
39 - chown -R root /var/lib/postgresql/9.3/main
40 - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.3/bin/initdb -D /shared/postgres_data || exit 0"
41 - chown -R postgres:postgres /shared/postgres_data
42 - chown -R postgres:postgres /var/run/postgresql
43
44 - replace:
45 filename: "/etc/postgresql/9.3/main/postgresql.conf"
46 from: "data_directory = '/var/lib/postgresql/9.3/main'"
47 to: "data_directory = '/shared/postgres_data'"
48
49 # listen on all interfaces
50 - replace:
51 filename: "/etc/postgresql/9.3/main/postgresql.conf"
52 from: /#?listen_addresses *=.*/
53 to: "listen_addresses = '*'"
54
55 - replace:
56 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
57 from: /^#local +replication +postgres +peer$/
58 to: "local replication postgres peer"
59
60 # allow all to connect in with md5 auth
61 - replace:
62 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
63 from: /^host.*all.*all.*127.*$/
64 to: "host all all 0.0.0.0/0 md5"
65
66 - exec:
67 background: true
68 # use fast shutdown for pg
69 stop_signal: INT
70 cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main
71
72 # give db a few secs to start up
73 - exec: "sleep 5"
74
75 - exec:
76 hook: postgres
77 cmd: "echo postgres installed!"