nginx startup: mkdir -p /var/log/nginx
[discourse_docker.git] / templates / postgres.9.2.template.yml
CommitLineData
9b9cdd3b
S
1hooks:
2 after_cron:
3 - file:
4 path: /var/lib/postgresql/take-database-backup
5 chown: postgres:postgres
6 chmod: "+x"
7 contents: |
8 #!/bin/bash
9 ID=db-$(date +%F_%T)
10 FILENAME=/shared/postgres_backup/$ID.tar.gz
11 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
12 echo $FILENAME
13
14 - file:
15 path: /var/spool/cron/crontabs/postgres
16 contents: |
17 # m h dom mon dow command
18 #MAILTO=?
19 0 */4 * * * /var/lib/postgresql/take-database-backup
20
21 before_code:
9b9cdd3b
S
22 - replace:
23 filename: /etc/service/unicorn/run
24 from: "# postgres"
25 to: sv start postgres || exit 1
26
27run:
28 # temporary
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
36 - file:
37 path: /etc/service/postgres/run
38 chmod: "+x"
39 contents: |
40 #!/bin/sh
41 exec 2>&1
42 exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main
43
44 - exec:
45 cmd:
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
49
50 - replace:
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'"
54
55 # listen on all interfaces
56 - replace:
57 filename: "/etc/postgresql/9.2/main/postgresql.conf"
58 from: /#?listen_addresses *=.*/
59 to: "listen_addresses = '*'"
60
61 # Necessary to enable backups
62 - exec:
63 cmd:
64 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
65
66 - replace:
67 filename: "/etc/postgresql/9.2/main/postgresql.conf"
68 from: /#?max_wal_senders *=.*/
69 to: "max_wal_senders = 4"
70
71 - replace:
72 filename: "/etc/postgresql/9.2/main/postgresql.conf"
73 from: /#?wal_level *=.*/
74 to: "wal_level = hot_standby"
75
76 - replace:
77 filename: "/etc/postgresql/9.2/main/pg_hba.conf"
78 from: /^#local +replication +postgres +peer$/
79 to: "local replication postgres peer"
80
81 # allow all to connect in with md5 auth
82 - replace:
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"
86
87 - exec:
88 background: true
89 cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"
90
91 # give db a few secs to start up
92 - exec: "sleep 5"
93
94 - exec: sudo -u postgres createdb discourse || exit 0
95 - exec:
96 stdin: |
97 create user discourse;
98 cmd: sudo -u postgres psql discourse
99 raise_on_fail: false
100
101 - exec:
102 stdin: |
103 grant all privileges on database discourse to discourse;
104 cmd: sudo -u postgres psql discourse
105 raise_on_fail: false
106
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;"'
110
111 - exec:
112 hook: postgres
113 cmd: "echo postgres installed!"