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