Commit | Line | Data |
---|---|---|
9b9cdd3b S |
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 | - 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 | ||
31 | run: | |
32 | # temporary | |
33 | - exec: apt-get install -y socat | |
34 | - exec: mkdir -p /shared/postgres_run | |
35 | - exec: chown postgres:postgres /shared/postgres_run | |
36 | - exec: chmod 775 /shared/postgres_run | |
37 | - exec: rm -fr /var/run/postgresql | |
38 | - exec: ln -s /shared/postgres_run /var/run/postgresql | |
39 | - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1 | |
40 | - file: | |
41 | path: /etc/service/postgres/run | |
42 | chmod: "+x" | |
43 | contents: | | |
44 | #!/bin/sh | |
45 | exec 2>&1 | |
46 | exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main | |
47 | ||
48 | - exec: | |
49 | cmd: | |
50 | - chown -R root /var/lib/postgresql/9.2/main | |
51 | - "[ ! -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" | |
52 | - chown -R postgres:postgres /shared/postgres_data | |
53 | ||
54 | - replace: | |
55 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
56 | from: "data_directory = '/var/lib/postgresql/9.2/main'" | |
57 | to: "data_directory = '/shared/postgres_data'" | |
58 | ||
59 | # listen on all interfaces | |
60 | - replace: | |
61 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
62 | from: /#?listen_addresses *=.*/ | |
63 | to: "listen_addresses = '*'" | |
64 | ||
65 | # Necessary to enable backups | |
66 | - exec: | |
67 | cmd: | |
68 | - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup | |
69 | ||
70 | - replace: | |
71 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
72 | from: /#?max_wal_senders *=.*/ | |
73 | to: "max_wal_senders = 4" | |
74 | ||
75 | - replace: | |
76 | filename: "/etc/postgresql/9.2/main/postgresql.conf" | |
77 | from: /#?wal_level *=.*/ | |
78 | to: "wal_level = hot_standby" | |
79 | ||
80 | - replace: | |
81 | filename: "/etc/postgresql/9.2/main/pg_hba.conf" | |
82 | from: /^#local +replication +postgres +peer$/ | |
83 | to: "local replication postgres peer" | |
84 | ||
85 | # allow all to connect in with md5 auth | |
86 | - replace: | |
87 | filename: "/etc/postgresql/9.2/main/pg_hba.conf" | |
88 | from: /^host.*all.*all.*127.*$/ | |
89 | to: "host all all 0.0.0.0/0 md5" | |
90 | ||
91 | - exec: | |
92 | background: true | |
93 | cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main" | |
94 | ||
95 | # give db a few secs to start up | |
96 | - exec: "sleep 5" | |
97 | ||
98 | - exec: sudo -u postgres createdb discourse || exit 0 | |
99 | - exec: | |
100 | stdin: | | |
101 | create user discourse; | |
102 | cmd: sudo -u postgres psql discourse | |
103 | raise_on_fail: false | |
104 | ||
105 | - exec: | |
106 | stdin: | | |
107 | grant all privileges on database discourse to discourse; | |
108 | cmd: sudo -u postgres psql discourse | |
109 | raise_on_fail: false | |
110 | ||
111 | - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "alter schema public owner to discourse;"' | |
112 | - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"' | |
113 | - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"' | |
114 | ||
115 | - exec: | |
116 | hook: postgres | |
117 | cmd: "echo postgres installed!" |