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