Commit | Line | Data |
---|---|---|
6f99f3c2 S |
1 | params: |
2 | db_synchronous_commit: "off" | |
3 | db_shared_buffers: "256MB" | |
4 | db_work_mem: "10MB" | |
8019560c | 5 | db_default_text_search_config: "pg_catalog.english" |
6f99f3c2 | 6 | |
9fb5f2d3 | 7 | hooks: |
9fb5f2d3 | 8 | before_code: |
9fb5f2d3 SS |
9 | - replace: |
10 | filename: /etc/service/unicorn/run | |
11 | from: "# postgres" | |
12 | to: sv start postgres || exit 1 | |
13 | ||
9fb5f2d3 | 14 | run: |
d7ed7814 SS |
15 | - exec: mkdir -p /shared/postgres_run |
16 | - exec: chown postgres:postgres /shared/postgres_run | |
17 | - exec: chmod 775 /shared/postgres_run | |
18 | - exec: rm -fr /var/run/postgresql | |
19 | - exec: ln -s /shared/postgres_run /var/run/postgresql | |
20 | - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1 | |
61975bbd SS |
21 | - exec: rm -fr /shared/postgres_run/.s* |
22 | - exec: rm -fr /shared/postgres_run/*.pid | |
9fb5f2d3 SS |
23 | - file: |
24 | path: /etc/service/postgres/run | |
25 | chmod: "+x" | |
26 | contents: | | |
27 | #!/bin/sh | |
28 | exec 2>&1 | |
56e5e6c2 | 29 | HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main |
d69fe0fb S |
30 | - file: |
31 | path: /root/upgrade_postgres | |
32 | chmod: "+x" | |
33 | contents: | | |
34 | #!/bin/bash | |
35 | if [ "9.2" = `cat /shared/postgres_data/PG_VERSION` ]; then | |
36 | echo Upgrading PostgreSQL to from version 9.2 to 9.3 | |
37 | rm -fr /shared/postgres_data_new | |
38 | install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/9.3/bin/initdb -D /shared/postgres_data_new || exit 0 | |
a0958e4f | 39 | apt-get update |
d69fe0fb | 40 | apt-get install -y postgresql-9.2 |
61975bbd SS |
41 | /etc/init.d/postgresql stop |
42 | rm -fr /shared/postgres_data/postmaster.pid | |
d69fe0fb | 43 | cd ~postgres |
61975bbd SS |
44 | cp /etc/postgresql/9.2/main/*.conf /shared/postgres_data |
45 | echo >> /shared/postgres_data/postgresql.conf | |
46 | echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf | |
9b9cdd3b S |
47 | SUCCESS=true |
48 | sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/9.2/bin -B /usr/lib/postgresql/9.3/bin || SUCCESS=false | |
49 | ||
50 | if [[ "$SUCCESS" == 'false' ]]; then | |
51 | echo ------------------------------------------------------------------------------------- | |
52 | echo UPGRADE OF POSTGRES FAILED | |
53 | echo | |
54 | echo You are going to need to export your data and import into a clean instance: | |
55 | echo | |
56 | echo Add the line: 'base_image: "samsaffron/discourse:0.1.1"' | |
57 | echo Change: "templates/postgres.template.yml TO templates/postgres.9.2.template.yml" | |
58 | echo | |
59 | echo Run "./launcher bootstrap" again | |
60 | echo | |
61 | echo When your instance is running: | |
62 | echo - Go to the admin UI, enable readonly and backup your site | |
63 | echo | |
64 | echo Then destroy your container "./launcher destroy standalone" | |
65 | echo Undo the base_image and postgres.9.2 template from your container config | |
66 | echo Run: "sudo mv /var/docker/shared/postgres_data /var/shared/postgres_data_old" | |
67 | echo Run: "./launcher bootstrap" | |
68 | echo | |
62418f96 | 69 | echo "Login to the blank site, and import your backup (remember to set the allow_restore site setting)" |
9b9cdd3b S |
70 | echo Restart your container: "./launcher restart" |
71 | echo ------------------------------------------------------------------------------------- | |
72 | exit 1 | |
73 | fi | |
74 | ||
d69fe0fb S |
75 | mv /shared/postgres_data /shared/postgres_data_old |
76 | mv /shared/postgres_data_new /shared/postgres_data | |
77 | ||
78 | echo ------------------------------------------------------------------------------------- | |
79 | echo UPGRADE OF POSTGRES COMPLETE | |
80 | echo | |
81 | echo Old 9.2 database is stored at /shared/postgres_data_old | |
82 | echo | |
83 | echo Please run "./launcher bootstrap" again | |
84 | echo ------------------------------------------------------------------------------------- | |
85 | exit 1 | |
86 | fi | |
9fb5f2d3 SS |
87 | - exec: |
88 | cmd: | |
d69fe0fb | 89 | - chown -R root /var/lib/postgresql/9.3/main |
3cb3d9c4 | 90 | - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.3/bin/initdb -D /shared/postgres_data || exit 0" |
9fb5f2d3 | 91 | - chown -R postgres:postgres /shared/postgres_data |
d69fe0fb | 92 | - chown -R postgres:postgres /var/run/postgresql |
9fb5f2d3 | 93 | |
61975bbd | 94 | - exec: /root/upgrade_postgres |
6f99f3c2 S |
95 | - exec: rm /root/upgrade_postgres |
96 | ||
9fb5f2d3 | 97 | - replace: |
d69fe0fb S |
98 | filename: "/etc/postgresql/9.3/main/postgresql.conf" |
99 | from: "data_directory = '/var/lib/postgresql/9.3/main'" | |
9fb5f2d3 SS |
100 | to: "data_directory = '/shared/postgres_data'" |
101 | ||
80c11be3 SS |
102 | # listen on all interfaces |
103 | - replace: | |
d69fe0fb | 104 | filename: "/etc/postgresql/9.3/main/postgresql.conf" |
80c11be3 SS |
105 | from: /#?listen_addresses *=.*/ |
106 | to: "listen_addresses = '*'" | |
107 | ||
6f99f3c2 S |
108 | # sync commit off is faster and less spiky, also marginally less safe |
109 | - replace: | |
110 | filename: "/etc/postgresql/9.3/main/postgresql.conf" | |
111 | from: /#?synchronous_commit *=.*/ | |
112 | to: "synchronous_commit = $db_synchronous_commit" | |
113 | ||
114 | # default is 128MB which is way too small | |
115 | - replace: | |
116 | filename: "/etc/postgresql/9.3/main/postgresql.conf" | |
117 | from: /#?shared_buffers *=.*/ | |
118 | to: "shared_buffers = $db_shared_buffers" | |
119 | ||
120 | # default is 1MB which is too small | |
121 | - replace: | |
122 | filename: "/etc/postgresql/9.3/main/postgresql.conf" | |
123 | from: /#?work_mem *=.*/ | |
124 | to: "work_mem = $db_work_mem" | |
125 | ||
126 | # allow for other | |
127 | - replace: | |
128 | filename: "/etc/postgresql/9.3/main/postgresql.conf" | |
129 | from: /#?default_text_search_config *=.*/ | |
130 | to: "default_text_search_config = '$db_default_text_search_config'" | |
131 | ||
9fb5f2d3 SS |
132 | # Necessary to enable backups |
133 | - exec: | |
134 | cmd: | |
135 | - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup | |
136 | ||
137 | - replace: | |
d69fe0fb | 138 | filename: "/etc/postgresql/9.3/main/postgresql.conf" |
9fb5f2d3 SS |
139 | from: /#?max_wal_senders *=.*/ |
140 | to: "max_wal_senders = 4" | |
141 | ||
142 | - replace: | |
d69fe0fb | 143 | filename: "/etc/postgresql/9.3/main/postgresql.conf" |
9fb5f2d3 SS |
144 | from: /#?wal_level *=.*/ |
145 | to: "wal_level = hot_standby" | |
146 | ||
147 | - replace: | |
d69fe0fb | 148 | filename: "/etc/postgresql/9.3/main/pg_hba.conf" |
9fb5f2d3 SS |
149 | from: /^#local +replication +postgres +peer$/ |
150 | to: "local replication postgres peer" | |
80c11be3 SS |
151 | |
152 | # allow all to connect in with md5 auth | |
153 | - replace: | |
d69fe0fb | 154 | filename: "/etc/postgresql/9.3/main/pg_hba.conf" |
80c11be3 SS |
155 | from: /^host.*all.*all.*127.*$/ |
156 | to: "host all all 0.0.0.0/0 md5" | |
157 | ||
158 | - exec: | |
159 | background: true | |
e56a65f6 | 160 | cmd: su - postgres -c '/usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main' |
80c11be3 SS |
161 | |
162 | # give db a few secs to start up | |
163 | - exec: "sleep 5" | |
164 | ||
e56a65f6 MB |
165 | - exec: su postgres -c 'createdb discourse' || true |
166 | - exec: su postgres -c 'psql discourse -c "create user discourse;"' || true | |
167 | - exec: su postgres -c 'psql discourse -c "grant all privileges on database discourse to discourse;"' || true | |
168 | - exec: su postgres -c 'psql discourse -c "alter schema public owner to discourse;"' | |
7f4eef4c | 169 | - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"' |
170 | - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' | |
e56a65f6 MB |
171 | - exec: su postgres -c 'psql discourse -c "create extension if not exists hstore;"' |
172 | - exec: su postgres -c 'psql discourse -c "create extension if not exists pg_trgm;"' | |
80c11be3 | 173 | |
be82e068 S |
174 | - file: |
175 | path: /var/lib/postgresql/take-database-backup | |
176 | chown: postgres:postgres | |
177 | chmod: "+x" | |
178 | contents: | | |
179 | #!/bin/bash | |
180 | ID=db-$(date +%F_%T) | |
181 | FILENAME=/shared/postgres_backup/$ID.tar.gz | |
182 | pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME | |
183 | echo $FILENAME | |
184 | ||
185 | - file: | |
186 | path: /var/spool/cron/crontabs/postgres | |
187 | contents: | | |
188 | # m h dom mon dow command | |
189 | #MAILTO=? | |
e56a65f6 | 190 | #0 */4 * * * /var/lib/postgresql/take-database-backup |
be82e068 | 191 | |
80c11be3 SS |
192 | - exec: |
193 | hook: postgres | |
194 | cmd: "echo postgres installed!" |