Commit | Line | Data |
---|---|---|
9fb5f2d3 SS |
1 | hooks: |
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 | ||
53 | ||
54 | run: | |
55 | ||
56 | - file: | |
57 | path: /etc/service/postgres/run | |
58 | chmod: "+x" | |
59 | contents: | | |
60 | #!/bin/sh | |
61 | exec 2>&1 | |
62 | exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main | |
63 | ||
64 | - exec: | |
65 | cmd: | |
66 | - chown -R root /var/lib/postgresql/9.2/main | |
67 | - "[ ! -e /shared/postgres_data ] && cp -r /var/lib/postgresql/9.2/main /shared/postgres_data || exit 0" | |
68 | - chown -R postgres:postgres /shared/postgres_data | |
69 | ||
70 | - replace: | |
71 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
72 | from: "data_directory = '/var/lib/postgresql/9.2/main'" | |
73 | to: "data_directory = '/shared/postgres_data'" | |
74 | ||
75 | # Necessary to enable backups | |
76 | - exec: | |
77 | cmd: | |
78 | - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup | |
79 | ||
80 | - replace: | |
81 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
82 | from: /#?max_wal_senders *=.*/ | |
83 | to: "max_wal_senders = 4" | |
84 | ||
85 | - replace: | |
86 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
87 | from: /#?wal_level *=.*/ | |
88 | to: "wal_level = hot_standby" | |
89 | ||
90 | - replace: | |
91 | filename: "/etc/postgresql/9.2/main/pg_hba.conf" | |
92 | from: /^#local +replication +postgres +peer$/ | |
93 | to: "local replication postgres peer" |