improve readme
[discourse_docker.git] / templates / postgres.template.yml
CommitLineData
9fb5f2d3
SS
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:
22 - exec:
23 background: true
24 cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"
25
26 # give db a few secs to start up
27 - exec: "sleep 5"
28
29 - exec: sudo -u postgres createdb discourse || exit 0
30 - exec:
31 stdin: |
32 create user discourse;
33 cmd: sudo -u postgres psql discourse
34 raise_on_fail: false
35
36 - exec:
37 stdin: |
38 grant all privileges on database discourse to discourse;
39 cmd: sudo -u postgres psql discourse
40 raise_on_fail: false
41
42 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"'
43 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"'
44 - replace:
45 filename: /etc/service/sidekiq/run
46 from: "# postgres"
47 to: sv start postgres || exit 1
48 - replace:
49 filename: /etc/service/unicorn/run
50 from: "# postgres"
51 to: sv start postgres || exit 1
52
9fb5f2d3 53run:
9fb5f2d3
SS
54 - file:
55 path: /etc/service/postgres/run
56 chmod: "+x"
57 contents: |
58 #!/bin/sh
59 exec 2>&1
60 exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main
61
62 - exec:
63 cmd:
64 - chown -R root /var/lib/postgresql/9.2/main
2162f1d4 65 - "[ ! -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"
9fb5f2d3
SS
66 - chown -R postgres:postgres /shared/postgres_data
67
68 - replace:
69 filename: "/etc/postgresql/9.2/main/postgresql.conf"
70 from: "data_directory = '/var/lib/postgresql/9.2/main'"
71 to: "data_directory = '/shared/postgres_data'"
72
73 # Necessary to enable backups
74 - exec:
75 cmd:
76 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
77
78 - replace:
79 filename: "/etc/postgresql/9.2/main/postgresql.conf"
80 from: /#?max_wal_senders *=.*/
81 to: "max_wal_senders = 4"
82
83 - replace:
84 filename: "/etc/postgresql/9.2/main/postgresql.conf"
85 from: /#?wal_level *=.*/
86 to: "wal_level = hot_standby"
87
88 - replace:
89 filename: "/etc/postgresql/9.2/main/pg_hba.conf"
90 from: /^#local +replication +postgres +peer$/
91 to: "local replication postgres peer"