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

View file

@ -7,6 +7,13 @@ mkdir -p /app/data/storage
# do not rely on WORKDIR # do not rely on WORKDIR
cd /app/code/server 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() { first_time_setup() {
sleep 10 sleep 10
@ -21,30 +28,13 @@ first_time_setup() {
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
echo "==> Installing LDAP plugin" 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 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 fi
} }
update_ldap() { update_config() {
echo "==> Updating Ldap credentials" 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'"
}
# cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
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) &
else
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
fi
echo "==> Updating configs"
yq eval ".webserver.hostname = \"${CLOUDRON_APP_DOMAIN}\"" -i /app/data/production.yaml yq eval ".webserver.hostname = \"${CLOUDRON_APP_DOMAIN}\"" -i /app/data/production.yaml
# database # database
@ -69,6 +59,7 @@ yq eval ".smtp.tls = false" -i /app/data/production.yaml
yq eval ".smtp.disable_starttls = true" -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 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 # 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.maxFileSize)" -i /app/data/production.yaml
yq eval "del(.log.rotation.maxFiles)" -i /app/data/production.yaml yq eval "del(.log.rotation.maxFiles)" -i /app/data/production.yaml
@ -77,9 +68,23 @@ 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.rotation.max_files = 1" -i /app/data/production.yaml
yq eval ".log.anonymizeIP = false" -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 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
if [[ ! -f "/app/data/production.yaml" ]]; then
echo "==> First run. creating config"
cp /app/pkg/production.yaml.example /app/data/production.yaml
update_config
first_time_setup &
else
update_config
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
echo "==> Migrate HLS paths to new for v4" echo "==> Migrate HLS paths to new for v4"
node dist/scripts/migrations/peertube-4.0.js node dist/scripts/migrations/peertube-4.0.js
fi
chown -R cloudron:cloudron /app/data chown -R cloudron:cloudron /app/data