Skip to content

Commit d47aad2

Browse files
DEV: allow for 2 container data services to setup on boot
allow postgres templates to assign themselves a DB password allows 2 container setups to be able to create db on boot and setup passwords move missing folder check to data services when running images without unicorn standalone just needs to wait for db to setup via the postgres service start script exit if migrate or precompile on boot fail so services retry gracefully when db is not yet up.
1 parent 64f31db commit d47aad2

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

samples/data.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ templates:
99
# any extra arguments for Docker?
1010
# docker_args:
1111

12+
# TODO: SOME_SECRET to a password for the discourse user
1213
params:
1314
db_default_text_search_config: "pg_catalog.english"
15+
db_password: SOME_SECRET
1416

1517
## Set db_shared_buffers to a max of 25% of the total memory.
1618
## will be set automatically by bootstrap based on detected RAM, or you can override
@@ -24,6 +26,7 @@ env:
2426
LC_ALL: en_US.UTF-8
2527
LANG: en_US.UTF-8
2628
LANGUAGE: en_US.UTF-8
29+
DISCOURSE_DB_PASSWORD: $db_password
2730

2831
volumes:
2932
- volume:
@@ -33,12 +36,11 @@ volumes:
3336
host: /var/discourse/shared/data/log/var-log
3437
guest: /var/log
3538

36-
# TODO: SOME_SECRET to a password for the discourse user
3739
hooks:
3840
after_postgres:
3941
- exec:
4042
stdin: |
41-
alter user discourse with password 'SOME_SECRET';
43+
alter user discourse with password '$db_password';
4244
cmd: su - postgres -c 'psql discourse'
4345

4446
raise_on_fail: false

templates/postgres.15.template.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,35 @@ hooks:
1414
- replace:
1515
filename: /etc/service/unicorn/run
1616
from: "# postgres"
17-
to: |
18-
if [ -f /root/install_postgres ]; then
19-
/root/install_postgres
20-
rm /root/install_postgres
21-
fi
22-
sv start postgres || exit 1
17+
to: sv start postgres || exit 1
2318

2419
run:
20+
- file:
21+
path: /etc/service/config-postgres/run
22+
chmod: "+x"
23+
contents: |
24+
#!/bin/sh
25+
if [ -f /usr/local/bin/create_db ] && [ "$CREATE_DB_ON_BOOT" = "1" ]; then
26+
sleep 5
27+
/usr/local/bin/create_db
28+
if [ ! -z "$DISCOURSE_DB_PASSWORD" ]; then
29+
echo "alter user discourse with password '$DISCOURSE_DB_PASSWORD';" | su - postgres -c 'psql $db_name'
30+
fi
31+
fi
32+
2533
- file:
2634
path: /etc/service/postgres/run
2735
chmod: "+x"
2836
contents: |
2937
#!/bin/sh
3038
exec 2>&1
39+
if [ -f /root/install_postgres ]; then
40+
/root/install_postgres
41+
rm /root/install_postgres
42+
fi
43+
if [ "$CREATE_DB_ON_BOOT" = "1" ]; then
44+
sv once config-postgres
45+
fi
3146
HOME=/var/lib/postgresql USER=postgres exec thpoff chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main
3247
3348
- file:

templates/postgres.template.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,35 @@ hooks:
1515
- replace:
1616
filename: /etc/service/unicorn/run
1717
from: "# postgres"
18-
to: |
19-
if [ -f /root/install_postgres ]; then
20-
/root/install_postgres
21-
rm /root/install_postgres
22-
fi
23-
sv start postgres || exit 1
18+
to: sv start postgres || exit 1
2419

2520
run:
21+
- file:
22+
path: /etc/service/config-postgres/run
23+
chmod: "+x"
24+
contents: |
25+
#!/bin/sh
26+
if [ -f /usr/local/bin/create_db ] && [ "$CREATE_DB_ON_BOOT" = "1" ]; then
27+
sleep 5
28+
/usr/local/bin/create_db
29+
if [ ! -z "$DISCOURSE_DB_PASSWORD" ]; then
30+
echo "alter user discourse with password '$DISCOURSE_DB_PASSWORD';" | su - postgres -c 'psql $db_name'
31+
fi
32+
fi
33+
2634
- file:
2735
path: /etc/service/postgres/run
2836
chmod: "+x"
2937
contents: |
3038
#!/bin/sh
3139
exec 2>&1
40+
if [ -f /root/install_postgres ]; then
41+
/root/install_postgres
42+
rm /root/install_postgres
43+
fi
44+
if [ "$CREATE_DB_ON_BOOT" = "1" ]; then
45+
sv once config-postgres
46+
fi
3247
HOME=/var/lib/postgresql USER=postgres exec thpoff chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main
3348
3449
- file:

templates/redis.template.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ run:
99
contents: |
1010
#!/bin/sh
1111
exec 2>&1
12+
if [ ! -d /shared/redis_data ]; then
13+
install -d -m 0755 -o redis -g redis /shared/redis_data
14+
fi
1215
exec thpoff chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf
1316
- file:
1417
path: /etc/service/redis/log/run
@@ -87,8 +90,4 @@ hooks:
8790
- replace:
8891
filename: /etc/service/unicorn/run
8992
from: "# redis"
90-
to: |
91-
if [ ! -d /shared/redis_data ]; then
92-
install -d -m 0755 -o redis -g redis /shared/redis_data
93-
fi
94-
sv start redis || exit 1
93+
to: sv start redis || exit 1

templates/web.template.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ run:
6161
if [[ -z "$PRECOMPILE_ON_BOOT" ]]; then
6262
PRECOMPILE_ON_BOOT=1
6363
fi
64-
if [ -f /usr/local/bin/create_db ] && [ "$CREATE_DB_ON_BOOT" = "1" ]; then /usr/local/bin/create_db; fi;
65-
if [ "$MIGRATE_ON_BOOT" = "1" ]; then su discourse -c 'bundle exec rake db:migrate'; fi
66-
if [ "$PRECOMPILE_ON_BOOT" = "1" ]; then SKIP_EMBER_CLI_COMPILE=1 su discourse -c 'bundle exec rake assets:precompile'; fi
64+
if [ "$MIGRATE_ON_BOOT" = "1" ]; then su discourse -c 'bundle exec rake db:migrate' || exit 1; fi
65+
if [ "$PRECOMPILE_ON_BOOT" = "1" ]; then SKIP_EMBER_CLI_COMPILE=1 su discourse -c 'bundle exec rake assets:precompile' || exit 1; fi
6766
LD_PRELOAD=$RUBY_ALLOCATOR HOME=/home/discourse USER=discourse exec thpoff chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
6867
6968
- file:

0 commit comments

Comments
 (0)