Commit 80ddc397 authored by Boxiang Sun's avatar Boxiang Sun

peertube: Configure database

parent 82c2efcf
...@@ -6,7 +6,6 @@ parts = ...@@ -6,7 +6,6 @@ parts =
service-redis service-redis
promise-redis promise-redis
postgresql postgresql
postgresql-extension
nginx-service nginx-service
nginx-listen-promise nginx-listen-promise
peertube-service peertube-service
...@@ -68,15 +67,21 @@ init = ...@@ -68,15 +67,21 @@ init =
with open(options['production_config_template'], "r", encoding='utf-8') as config_template_file: with open(options['production_config_template'], "r", encoding='utf-8') as config_template_file:
with open(options['production_config_prod'], "w", encoding='utf-8') as config_prod_file: with open(options['production_config_prod'], "w", encoding='utf-8') as config_prod_file:
print('Fuck!!!') local_host_counter = 0
print(options['production_config_template'])
print(options['production_config_prod'])
for line in config_template_file: for line in config_template_file:
if "hostname: 'example.com'" in line: if "hostname: 'example.com'" in line:
line = line.replace("example.com", "https://[$${nginx-configuration:ip}]/$${nginx-configuration:port}") line = line.replace("example.com", "https://[$${nginx-configuration:ip}]/$${nginx-configuration:port}")
if "password: 'peertube'" in line: elif "password: 'peertube'" in line:
line = line.replace("peertube", "$${postgresql:password}") line = line.replace("peertube", "$${postgresql:password}")
if "/var/www/peertube" in line: elif "hostname: 'localhost'" in line:
local_host_counter += 1
if local_host_counter == 2:
line = line.replace("localhost", "$${postgresql:ipv4}")
if local_host_counter == 3:
line = '' # set 'hostname' and 'port' to null, use redis.socket
elif "6379" in line:
line = line.replace("port: 6379", "unixsocket: $${service-redis:unixsocket}") # set 'hostname' and 'port' to null, use redis.socket
elif "/var/www/peertube" in line:
line = line.replace("/var/www/peertube", "$${directory:peertube_directory}") line = line.replace("/var/www/peertube", "$${directory:peertube_directory}")
config_prod_file.write(line) config_prod_file.write(line)
...@@ -102,13 +107,6 @@ ipv4 = $${instance-parameter:ipv4-random} ...@@ -102,13 +107,6 @@ ipv4 = $${instance-parameter:ipv4-random}
ipv6 = ipv6 =
port = 5432 port = 5432
[postgresql-extension]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:bin}/$${:_buildout_section_name_}
command-line =
$${postgresql:bin}/psql -c "CREATE EXTENSION pg_trgm;" $${postgresql:dbname}
$${postgresql:bin}/psql -c "CREATE EXTENSION unaccent;" $${postgresql:dbname}
[service-postgresql] [service-postgresql]
recipe = slapos.cookbook:postgres recipe = slapos.cookbook:postgres
bin = {{ postgresql_location }}/bin bin = {{ postgresql_location }}/bin
......
cd ${peertube:location} && cd ${peertube:location} &&
exec env NODE_ENV=production NODE_CONFIG_DIR=$${peertube-setup:peertube_config} \ # setup db
die() {
echo "$*" 1>&2
exit 1
}
# run psql on gitlab db
psql() {
$${postgresql:bin}/psql \
-h $${postgresql:pgdata-directory} \
-U $${postgresql:superuser} \
-d $${postgresql:dbname} \
"$@"
}
# initial db setup
# ( first quering PG several times waiting a bit till postgresql is started and ready )
tpgwait=5
while true; do
pgtables="$(psql -c '\d' 2>&1)" && break
tpgwait=$(( $tpgwait - 1 ))
test $tpgwait = 0 && die "pg query problem"
echo "I: PostgreSQL is not ready (yet ?); will retry $tpgwait times..." 1>&2
sleep 1
done
echo "I: PostgreSQL ready." 1>&2
# make sure pg_trgm extension is enabled for peertube db
# $${postgresql:bin}/psql -c 'CREATE EXTENSION IF NOT EXISTS pg_trgm;' $${postgresql:dbname} || die "pg_trgm setup failed"
# make sure unaccent extension is enabled for peertube db
# $${postgresql:bin}/psql -c 'CREATE EXTENSION IF NOT EXISTS unaccent;' $${postgresql:dbname} || die "unaccent setup failed"
exec env NODE_ENV=production NODE_CONFIG_DIR=$${peertube-setup:peertube_config} PATH=${ffmpeg:location}/bin:$PATH\
${nodejs:location}/bin/node ${peertube:location}/dist/server ${nodejs:location}/bin/node ${peertube:location}/dist/server
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment