Improve startup logic to make it more stable

This commit is contained in:
Johannes Zellner 2021-12-16 16:11:13 +01:00
parent b3895aab55
commit 8a6d5d5394
2 changed files with 63 additions and 58 deletions

View file

@ -74,19 +74,19 @@ email:
# From the project root directory
storage:
tmp: '/var/www/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before processing...
avatars: '/var/www/peertube/storage/avatars/'
videos: '/var/www/peertube/storage/videos/'
streaming_playlists: '/var/www/peertube/storage/streaming-playlists/'
redundancy: '/var/www/peertube/storage/redundancy/'
logs: '/var/www/peertube/storage/logs/'
previews: '/var/www/peertube/storage/previews/'
thumbnails: '/var/www/peertube/storage/thumbnails/'
torrents: '/var/www/peertube/storage/torrents/'
captions: '/var/www/peertube/storage/captions/'
cache: '/var/www/peertube/storage/cache/'
plugins: '/var/www/peertube/storage/plugins/'
client_overrides: '/var/www/peertube/storage/client-overrides/'
tmp: '/app/data/storage/tmp/' # Use to download data (imports etc), store uploaded files before processing...
avatars: '/app/data/storage/avatars/'
videos: '/app/data/storage/videos/'
streaming_playlists: '/app/data/storage/streaming-playlists/'
redundancy: '/app/data/storage/redundancy/'
logs: '/app/data/storage/logs/'
previews: '/app/data/storage/previews/'
thumbnails: '/app/data/storage/thumbnails/'
torrents: '/app/data/storage/torrents/'
captions: '/app/data/storage/captions/'
cache: '/app/data/storage/cache/'
plugins: '/app/data/storage/plugins/'
client_overrides: '/app/data/storage/client-overrides/'
log:
level: 'info' # debug/info/warning/error

View file

@ -7,6 +7,13 @@ mkdir -p /app/data/storage
# do not rely on WORKDIR
cd /app/code/server
update_ldap() {
echo "==> Updating Ldap credentials"
PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} \
-c "UPDATE plugin SET settings='{\"url\": \"${CLOUDRON_LDAP_URL}\", \"weight\": 100, \"insecure-tls\": false, \"bind-dn\": \"${CLOUDRON_LDAP_BIND_DN}\", \"bind-credentials\": \"${CLOUDRON_LDAP_BIND_PASSWORD}\", \"search-base\": \"${CLOUDRON_LDAP_USERS_BASE_DN}\", \"mail-property\": \"mail\", \"search-filter\": \"(|(mail={{username}})(username={{username}}))\", \"username-property\": \"username\"}' WHERE name='auth-ldap'"
}
first_time_setup() {
sleep 10
@ -21,14 +28,46 @@ first_time_setup() {
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
echo "==> Installing LDAP plugin"
cd /app/code/cli && node dist/server/tools/peertube.js plugins install -n peertube-plugin-auth-ldap --url "${CLOUDRON_APP_ORIGIN}" --username root --password changeme
update_ldap
fi
}
update_ldap() {
echo "==> Updating Ldap credentials"
update_config() {
echo "==> Ensure and updating configs"
PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} \
-c "UPDATE plugin SET settings='{\"url\": \"${CLOUDRON_LDAP_URL}\", \"weight\": 100, \"insecure-tls\": false, \"bind-dn\": \"${CLOUDRON_LDAP_BIND_DN}\", \"bind-credentials\": \"${CLOUDRON_LDAP_BIND_PASSWORD}\", \"search-base\": \"${CLOUDRON_LDAP_USERS_BASE_DN}\", \"mail-property\": \"mail\", \"search-filter\": \"(|(mail={{username}})(username={{username}}))\", \"username-property\": \"username\"}' WHERE name='auth-ldap'"
yq eval ".webserver.hostname = \"${CLOUDRON_APP_DOMAIN}\"" -i /app/data/production.yaml
# database
yq eval ".database.hostname = \"${CLOUDRON_POSTGRESQL_HOST}\"" -i /app/data/production.yaml
yq eval ".database.port = ${CLOUDRON_POSTGRESQL_PORT}" -i /app/data/production.yaml
yq eval ".database.username = \"${CLOUDRON_POSTGRESQL_USERNAME}\"" -i /app/data/production.yaml
yq eval ".database.password = \"${CLOUDRON_POSTGRESQL_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".database.name = \"${CLOUDRON_POSTGRESQL_DATABASE}\"" -i /app/data/production.yaml
yq eval "del(.database.suffix)" -i /app/data/production.yaml
# redis
yq eval ".redis.hostname = \"${CLOUDRON_REDIS_HOST}\"" -i /app/data/production.yaml
yq eval ".redis.port = ${CLOUDRON_REDIS_PORT}" -i /app/data/production.yaml
yq eval ".redis.auth = \"${CLOUDRON_REDIS_PASSWORD}\"" -i /app/data/production.yaml
# smtp
yq eval ".smtp.hostname = \"${CLOUDRON_MAIL_SMTP_SERVER}\"" -i /app/data/production.yaml
yq eval ".smtp.port = ${CLOUDRON_MAIL_SMTP_PORT}" -i /app/data/production.yaml
yq eval ".smtp.username = \"${CLOUDRON_MAIL_SMTP_USERNAME}\"" -i /app/data/production.yaml
yq eval ".smtp.password = \"${CLOUDRON_MAIL_SMTP_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".smtp.tls = false" -i /app/data/production.yaml
yq eval ".smtp.disable_starttls = true" -i /app/data/production.yaml
yq eval ".smtp.from_address = \"${CLOUDRON_MAIL_FROM}\"" -i /app/data/production.yaml
echo "==> Migrate config file attributes for v4"
# v4 config file migrations https://github.com/Chocobozzz/PeerTube/releases/tag/v4.0.0
yq eval "del(.log.rotation.maxFileSize)" -i /app/data/production.yaml
yq eval "del(.log.rotation.maxFiles)" -i /app/data/production.yaml
yq eval "del(.log.anonymizeIP)" -i /app/data/production.yaml
yq eval ".log.rotation.max_file_size = \"1MB\"" -i /app/data/production.yaml
yq eval ".log.rotation.max_files = 1" -i /app/data/production.yaml
yq eval ".log.anonymizeIP = false" -i /app/data/production.yaml
yq eval ".storage.bin = \"/app/data/storage/bin/\"" -i /app/data/production.yaml
}
# cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
@ -36,51 +75,17 @@ if [[ ! -f "/app/data/production.yaml" ]]; then
echo "==> First run. creating config"
cp /app/pkg/production.yaml.example /app/data/production.yaml
# this is sed because there are too many paths
sed -e 's,/var/www/peertube/storage,/app/data/storage,g' -i /app/data/production.yaml
(first_time_setup && update_ldap) &
update_config
first_time_setup &
else
update_config
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
echo "==> Migrate HLS paths to new for v4"
node dist/scripts/migrations/peertube-4.0.js
fi
echo "==> Updating configs"
yq eval ".webserver.hostname = \"${CLOUDRON_APP_DOMAIN}\"" -i /app/data/production.yaml
# database
yq eval ".database.hostname = \"${CLOUDRON_POSTGRESQL_HOST}\"" -i /app/data/production.yaml
yq eval ".database.port = ${CLOUDRON_POSTGRESQL_PORT}" -i /app/data/production.yaml
yq eval ".database.username = \"${CLOUDRON_POSTGRESQL_USERNAME}\"" -i /app/data/production.yaml
yq eval ".database.password = \"${CLOUDRON_POSTGRESQL_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".database.name = \"${CLOUDRON_POSTGRESQL_DATABASE}\"" -i /app/data/production.yaml
yq eval "del(.database.suffix)" -i /app/data/production.yaml
# redis
yq eval ".redis.hostname = \"${CLOUDRON_REDIS_HOST}\"" -i /app/data/production.yaml
yq eval ".redis.port = ${CLOUDRON_REDIS_PORT}" -i /app/data/production.yaml
yq eval ".redis.auth = \"${CLOUDRON_REDIS_PASSWORD}\"" -i /app/data/production.yaml
# smtp
yq eval ".smtp.hostname = \"${CLOUDRON_MAIL_SMTP_SERVER}\"" -i /app/data/production.yaml
yq eval ".smtp.port = ${CLOUDRON_MAIL_SMTP_PORT}" -i /app/data/production.yaml
yq eval ".smtp.username = \"${CLOUDRON_MAIL_SMTP_USERNAME}\"" -i /app/data/production.yaml
yq eval ".smtp.password = \"${CLOUDRON_MAIL_SMTP_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".smtp.tls = false" -i /app/data/production.yaml
yq eval ".smtp.disable_starttls = true" -i /app/data/production.yaml
yq eval ".smtp.from_address = \"${CLOUDRON_MAIL_FROM}\"" -i /app/data/production.yaml
# v4 config file migrations https://github.com/Chocobozzz/PeerTube/releases/tag/v4.0.0
yq eval "del(.log.rotation.maxFileSize)" -i /app/data/production.yaml
yq eval "del(.log.rotation.maxFiles)" -i /app/data/production.yaml
yq eval "del(.log.anonymizeIP)" -i /app/data/production.yaml
yq eval ".log.rotation.max_file_size = \"1MB\"" -i /app/data/production.yaml
yq eval ".log.rotation.max_files = 1" -i /app/data/production.yaml
yq eval ".log.anonymizeIP = false" -i /app/data/production.yaml
yq eval ".storage.bin = \"/app/data/storage/bin/\"" -i /app/data/production.yaml
echo "==> Migrate HLS paths to new for v4"
node dist/scripts/migrations/peertube-4.0.js
chown -R cloudron:cloudron /app/data
echo "==> Starting PeerTube"