diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 03813c479..706d2a64d 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -16,10 +16,6 @@ hooks: filename: /etc/service/unicorn/run from: "# postgres" to: | - if [ -f /root/install_postgres ]; then - /root/install_postgres - rm /root/install_postgres - fi sv start postgres || exit 1 run: @@ -29,6 +25,15 @@ run: contents: | #!/bin/sh exec 2>&1 + if [ -f /root/install_postgres ]; then + /root/install_postgres + rm /root/install_postgres + fi + if [ "$CREATE_DB_ON_BOOT" = "1" ]; then + sudo -E -u postgres /usr/lib/postgresql/15/bin/pg_ctl -D /etc/postgresql/15/main -o "-c listen_addresses='' -p 5432" -w start + /usr/local/bin/create_db + sudo -E -u postgres /usr/lib/postgresql/15/bin/pg_ctl -D /etc/postgresql/15/main -m fast -w stop + fi 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 - file: @@ -258,6 +263,9 @@ run: su postgres -c 'psql $db_name -c "create extension if not exists vector;"' su postgres -c 'psql $db_name -c "alter extension vector update;"' || true sudo -u postgres psql $db_name <<< "update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');" || true + if [ ! -z "$DISCOURSE_DB_PASSWORD" ]; then + echo "alter user $db_user with password '$DISCOURSE_DB_PASSWORD';" | su - postgres -c 'psql $db_name' + fi - file: path: /var/lib/postgresql/take-database-backup diff --git a/templates/redis.template.yml b/templates/redis.template.yml index b8ddd7e83..12b8cbce6 100644 --- a/templates/redis.template.yml +++ b/templates/redis.template.yml @@ -9,6 +9,7 @@ run: contents: | #!/bin/sh exec 2>&1 + install -d -m 0755 -o redis -g redis /shared/redis_data exec thpoff chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf - file: path: /etc/service/redis/log/run @@ -88,7 +89,4 @@ hooks: filename: /etc/service/unicorn/run from: "# redis" to: | - if [ ! -d /shared/redis_data ]; then - install -d -m 0755 -o redis -g redis /shared/redis_data - fi sv start redis || exit 1 diff --git a/templates/web.template.yml b/templates/web.template.yml index 920d06350..8333d52df 100644 --- a/templates/web.template.yml +++ b/templates/web.template.yml @@ -61,9 +61,12 @@ run: if [[ -z "$PRECOMPILE_ON_BOOT" ]]; then PRECOMPILE_ON_BOOT=1 fi - if [ -f /usr/local/bin/create_db ] && [ "$CREATE_DB_ON_BOOT" = "1" ]; then /usr/local/bin/create_db; fi; - if [ "$MIGRATE_ON_BOOT" = "1" ]; then su discourse -c 'bundle exec rake db:migrate'; fi - if [ "$PRECOMPILE_ON_BOOT" = "1" ]; then SKIP_EMBER_CLI_COMPILE=1 su discourse -c 'bundle exec rake assets:precompile'; fi + if [ "$MIGRATE_ON_BOOT" = "1" ]; then + su discourse -c 'bundle exec rake db:migrate' || exit 1 + fi + if [ "$PRECOMPILE_ON_BOOT" = "1" ]; then + SKIP_EMBER_CLI_COMPILE=1 su discourse -c 'bundle exec rake assets:precompile' || exit 1 + fi 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 - file: