1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/funkwhale_ynh.git synced 2024-09-03 18:36:24 +02:00

Move file structure to prevent backup of medias for upgrades

This commit is contained in:
Jean-Baptiste Holcroft 2018-10-21 10:59:28 +02:00
parent 6e9cba8011
commit 6d06ab4f2b
11 changed files with 95 additions and 58 deletions

View file

@ -17,6 +17,7 @@
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=11c81c1f503691272df5002dad8278bd82f34535 upgrade=1 from_commit=11c81c1f503691272df5002dad8278bd82f34535
upgrade=1 from_commit=80a5044d13a6782063fee2d7fb7a01832a6aa767
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=0 incorrect_path=0
@ -41,4 +42,7 @@ Notification=all
;;; Upgrade options ;;; Upgrade options
; commit=11c81c1f503691272df5002dad8278bd82f34535 ; commit=11c81c1f503691272df5002dad8278bd82f34535
name=Upgrade from 0.15~ynh2 name=Upgrade from 0.15~ynh2
manifest_arg=domain=DOMAIN&path=/&admin=USER&is_public=1
; commit=80a5044d13a6782063fee2d7fb7a01832a6aa767
name=Upgrade from 0.16.3
manifest_arg=domain=DOMAIN&path=/&admin=USER&is_public=1 manifest_arg=domain=DOMAIN&path=/&admin=USER&is_public=1

View file

@ -79,12 +79,12 @@ CACHE_URL=redis://127.0.0.1:6379/__REDIS_DB__
# Where media files (such as album covers or audio tracks) should be stored # Where media files (such as album covers or audio tracks) should be stored
# on your system? # on your system?
# (Ensure this directory actually exists) # (Ensure this directory actually exists)
MEDIA_ROOT=__FINALPATH__/data/media MEDIA_ROOT=__FINALPATH__/media
# Where static files (such as API css or icons) should be compiled # Where static files (such as API css or icons) should be compiled
# on your system? # on your system?
# (Ensure this directory actually exists) # (Ensure this directory actually exists)
STATIC_ROOT=__FINALPATH__/data/static STATIC_ROOT=__FINALPATH__/code/data/static
# Update it to match the domain that will be used to reach your funkwhale # Update it to match the domain that will be used to reach your funkwhale
# instance # instance
@ -119,8 +119,8 @@ RAVEN_DSN=https://44332e9fdd3d42879c7d35bf8562c6a4:0062dc16a22b41679cd5765e5342f
# MUSIC_DIRECTORY_PATH=/srv/funkwhale/data/music # MUSIC_DIRECTORY_PATH=/srv/funkwhale/data/music
# # MUSIC_DIRECTORY_SERVE_PATH= # stays commented, not needed # # MUSIC_DIRECTORY_SERVE_PATH= # stays commented, not needed
MUSIC_DIRECTORY_SERVE_PATH=__FINALPATH__/data/music MUSIC_DIRECTORY_SERVE_PATH=__FINALPATH__/import
MUSIC_DIRECTORY_PATH=__FINALPATH__/data/music MUSIC_DIRECTORY_PATH=__FINALPATH__/import
# LDAP settings # LDAP settings
# Use the following options to allow authentication on your Funkwhale instance # Use the following options to allow authentication on your Funkwhale instance

View file

@ -6,9 +6,9 @@ PartOf=__APP__.target
[Service] [Service]
User=__APP__ User=__APP__
# adapt this depending on the path of your funkwhale installation # adapt this depending on the path of your funkwhale installation
WorkingDirectory=__FINALPATH__/api WorkingDirectory=__FINALPATH__/code/api
EnvironmentFile=__FINALPATH__/config/.env EnvironmentFile=__FINALPATH__/code/config/.env
ExecStart=__FINALPATH__/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -6,9 +6,9 @@ PartOf=__APP__.target
[Service] [Service]
User=__APP__ User=__APP__
# adapt this depending on the path of your funkwhale installation # adapt this depending on the path of your funkwhale installation
WorkingDirectory=__FINALPATH__/api WorkingDirectory=__FINALPATH__/code/api
EnvironmentFile=__FINALPATH__/config/.env EnvironmentFile=__FINALPATH__/code/config/.env
ExecStart=__FINALPATH__/virtualenv/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers ExecStart=__FINALPATH__/code/virtualenv/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -6,9 +6,9 @@ PartOf=__APP__.target
[Service] [Service]
User=__APP__ User=__APP__
# adapt this depending on the path of your funkwhale installation # adapt this depending on the path of your funkwhale installation
WorkingDirectory=__FINALPATH__/api WorkingDirectory=__FINALPATH__/code/api
EnvironmentFile=__FINALPATH__/config/.env EnvironmentFile=__FINALPATH__/code/config/.env
ExecStart=__FINALPATH__/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,5 +1,5 @@
location / { location / {
alias __FINALPATH__/front/dist/; alias __FINALPATH__/code/front/dist/;
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
@ -13,24 +13,24 @@ location @rewrites {
} }
location /api/ { location /api/ {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
# this is needed if you have file import via upload enabled # this is needed if you have file import via upload enabled
client_max_body_size 30M; client_max_body_size 30M;
proxy_pass http://127.0.0.1:__PORT__/api/; proxy_pass http://127.0.0.1:__PORT__/api/;
} }
location /federation/ { location /federation/ {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
proxy_pass http://127.0.0.1:__PORT__/federation/; proxy_pass http://127.0.0.1:__PORT__/federation/;
} }
location /.well-known/ { location /.well-known/ {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
proxy_pass http://127.0.0.1:__PORT__/.well-known/; proxy_pass http://127.0.0.1:__PORT__/.well-known/;
} }
location /media/ { location /media/ {
alias __FINALPATH__/data/media/; alias __FINALPATH__/media/;
} }
location __PATH__/_protected/media/ { location __PATH__/_protected/media/ {
@ -38,7 +38,7 @@ location __PATH__/_protected/media/ {
# audio files once correct permission / authentication # audio files once correct permission / authentication
# has been checked on API side # has been checked on API side
internal; internal;
alias __FINALPATH__/data/media/; alias __FINALPATH__/media/;
} }
# Transcoding logic and caching # Transcoding logic and caching
@ -47,7 +47,7 @@ location __PATH__/_protected/media/ {
# https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache # https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache
location = /transcode-auth { location = /transcode-auth {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
# needed so we can authenticate transcode requests, but still # needed so we can authenticate transcode requests, but still
# cache the result # cache the result
internal; internal;
@ -62,7 +62,7 @@ location = /transcode-auth {
} }
location /api/v1/trackfiles/transcode/ { location /api/v1/trackfiles/transcode/ {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
# this block deals with authenticating and caching transcoding # this block deals with authenticating and caching transcoding
# requests. Caching is heavily recommended as transcoding # requests. Caching is heavily recommended as transcoding
# is a CPU intensive process. # is a CPU intensive process.
@ -82,15 +82,15 @@ location /api/v1/trackfiles/transcode/ {
location /staticfiles/ { location /staticfiles/ {
# django static files # django static files
alias __FINALPATH__/data/static/; alias __FINALPATH__/code/data/static/;
} }
location /rest/ { location /rest/ {
include __FINALPATH__/deploy/funkwhale_proxy.conf; include __FINALPATH__/code/deploy/funkwhale_proxy.conf;
proxy_pass http://127.0.0.1:__PORT__/api/subsonic/rest/; proxy_pass http://127.0.0.1:__PORT__/code/api/subsonic/rest/;
} }
location /_protected/music { location /_protected/music {
internal; internal;
alias __FINALPATH__/data/music; alias __FINALPATH__/import;
} }

View file

@ -38,7 +38,15 @@ db_name=$(ynh_app_setting_get "$app" db_name)
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup "$final_path" backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
# If backup_core_only have any value in the settings.yml file, do not backup the data directory
if [ -z "$backup_core_only" ]
then
ynh_backup "$final_path"
else
echo "Data dir will not be saved, because backup_core_only is set." >&2
ynh_backup "$final_path/code"
fi
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION

View file

@ -85,11 +85,12 @@ ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid "$app") db_name=$(ynh_sanitize_dbid "$app")
db_user=$db_name db_user=$db_name
db_pwd=$(ynh_string_random) db_pwd=$(ynh_string_random)
# Initialize database and store postgres password for upgrade
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd"
ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set "$app" psqlpwd "$db_pwd" ynh_app_setting_set "$app" psqlpwd "$db_pwd"
# Initialize database and store postgres password for upgrade
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd"
systemctl reload postgresql systemctl reload postgresql
#================================================= #=================================================
@ -98,12 +99,12 @@ systemctl reload postgresql
ynh_app_setting_set "$app" final_path "$final_path" ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source "$final_path/code"
ynh_setup_source "$final_path" "app-frontend" ynh_setup_source "$final_path/code" "app-frontend"
( (
cd "$final_path" cd "$final_path"
mkdir -p config api data/static data/media data/music front mkdir -p code/config code/api code/data/static media import code/front
) )
#================================================= #=================================================
@ -138,22 +139,22 @@ ynh_system_user_create "$app" "$final_path"
# PYTHON DEPENDENCIES # PYTHON DEPENDENCIES
#================================================= #=================================================
python3 -m venv "$final_path/virtualenv" python3 -m venv "$final_path/code/virtualenv"
( (
set +o nounset set +o nounset
source "${final_path}/virtualenv/bin/activate" source "${final_path}/code/virtualenv/bin/activate"
set -o nounset set -o nounset
pip install --upgrade pip pip install --upgrade pip
pip install --upgrade setuptools pip install --upgrade setuptools
pip install wheel pip install wheel
pip install -r "${final_path}/api/requirements.txt" pip install -r "${final_path}/code/api/requirements.txt"
) )
#================================================= #=================================================
# MODIFY THE CONFIG FILE # MODIFY THE CONFIG FILE
#================================================= #=================================================
configfile="$final_path/config/.env" configfile="$final_path/code/config/.env"
cp ../conf/env.prod "$configfile" cp ../conf/env.prod "$configfile"
@ -172,12 +173,12 @@ ynh_replace_string "__DBNAME__" "$app" "$configfile"
ynh_replace_string "__FINALPATH__" "$final_path" "$configfile" ynh_replace_string "__FINALPATH__" "$final_path" "$configfile"
ynh_replace_string "__KEY__" "$key" "$configfile" ynh_replace_string "__KEY__" "$key" "$configfile"
cat > "$final_path/load_env" <<'EOL' cat > "$final_path/code/load_env" <<'EOL'
#!/bin/bash #!/bin/bash
export $(cat "$final_path/config/.env" | grep -v ^# | xargs) export $(cat "$final_path/code/config/.env" | grep -v ^# | xargs)
EOL EOL
chmod +x "$final_path/load_env" chmod +x "$final_path/code/load_env"
#================================================= #=================================================
# MODIFY THE CONFIG FILE # MODIFY THE CONFIG FILE
@ -186,10 +187,10 @@ chmod +x "$final_path/load_env"
admin_mail=$(ynh_user_get_info "$admin" "mail") admin_mail=$(ynh_user_get_info "$admin" "mail")
( (
set +o nounset set +o nounset
source "${final_path}/virtualenv/bin/activate" source "${final_path}/code/virtualenv/bin/activate"
source "${final_path}/load_env" source "${final_path}/code/load_env"
set -o nounset set -o nounset
cd "$final_path" cd "$final_path/code/"
# needed for enabling the 'unaccent' extension # needed for enabling the 'unaccent' extension
ynh_psql_execute_as_root "ALTER USER $db_user WITH SUPERUSER;" ynh_psql_execute_as_root "ALTER USER $db_user WITH SUPERUSER;"
@ -220,7 +221,7 @@ systemctl restart "$app".target
#================================================= #=================================================
chown -R "$app": "$final_path" chown -R "$app": "$final_path"
chmod -R 755 "$final_path/front/dist/" chmod -R 755 "$final_path/code/front/dist/"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT

View file

@ -28,12 +28,13 @@ redis_db=$(ynh_app_setting_get $app redis_db)
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
systemctl stop "$app".target
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config "$app-server" ynh_remove_systemd_config "$app-server"
ynh_remove_systemd_config "$app-worker" ynh_remove_systemd_config "$app-worker"
ynh_remove_systemd_config "$app-beat" ynh_remove_systemd_config "$app-beat"
systemctl stop "$app".target
ynh_secure_remove "/etc/systemd/system/$app.target" ynh_secure_remove "/etc/systemd/system/$app.target"
#================================================= #=================================================

View file

@ -57,7 +57,18 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.conf"
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_restore_file "$final_path" backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
# If backup_core_only have any value, then restore only code
if [ -z "$backup_core_only" ]
then
ynh_restore_file "$final_path/code"
else
ynh_restore_file "$final_path"
fi
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete "$app" backup_core_only
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER

View file

@ -35,10 +35,21 @@ if [ -z "$redis_db" ]; then
ynh_app_setting_set "$app" redis_db "$redis_db" ynh_app_setting_set "$app" redis_db "$redis_db"
fi fi
# make sure we have the last code organization
if [ ! -d "$final_path/code/" ]; then
mkdir "$final_path/code"
mv "$final_path/!(code)" "$final_path/code/"
mv "$final_path/code/data/media" "$final_path/media"
mv "$final_path/code/data/music" "$final_path/import"
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
# Inform the backup/restore process that it should not save the data directory
ynh_app_setting_set "$app" backup_core_only 1
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
@ -63,12 +74,12 @@ path_url=$(ynh_normalize_url_path "$path_url")
ynh_app_setting_set "$app" final_path "$final_path" ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source "$final_path/code"
ynh_setup_source "$final_path" "app-frontend" ynh_setup_source "$final_path/code" "app-frontend"
( (
cd "$final_path" cd "$final_path"
mkdir -p config api data/static data/media data/music front mkdir -p code/config code/api code/data/static media import code/front
) )
#================================================= #=================================================
@ -118,15 +129,15 @@ ynh_install_app_dependencies build-essential curl ffmpeg \
# PYTHON DEPENDENCIES # PYTHON DEPENDENCIES
#================================================= #=================================================
python3 -m venv "$final_path/virtualenv" python3 -m venv "$final_path/code/virtualenv"
( (
set +o nounset set +o nounset
source "${final_path}/virtualenv/bin/activate" source "${final_path}/code/virtualenv/bin/activate"
set -o nounset set -o nounset
pip install --upgrade pip pip install --upgrade pip
pip install --upgrade setuptools pip install --upgrade setuptools
pip install wheel pip install wheel
pip install -r "${final_path}/api/requirements.txt" pip install -r "${final_path}/code/api/requirements.txt"
# https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16 # https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16
pip uninstall django-cacheops --yes pip uninstall django-cacheops --yes
@ -136,7 +147,7 @@ python3 -m venv "$final_path/virtualenv"
# MODIFY THE CONFIG FILE # MODIFY THE CONFIG FILE
#================================================= #=================================================
configfile="$final_path/config/.env" configfile="$final_path/code/config/.env"
cp ../conf/env.prod "$configfile" cp ../conf/env.prod "$configfile"
@ -153,12 +164,12 @@ ynh_replace_string "__DBNAME__" "$app" "$configfile"
ynh_replace_string "__FINALPATH__" "$final_path" "$configfile" ynh_replace_string "__FINALPATH__" "$final_path" "$configfile"
ynh_replace_string "__KEY__" "$key" "$configfile" ynh_replace_string "__KEY__" "$key" "$configfile"
cat > "$final_path/load_env" <<'EOL' cat > "$final_path/code/load_env" <<'EOL'
#!/bin/bash #!/bin/bash
export $(cat "$final_path/config/.env" | grep -v ^# | xargs) export $(cat "$final_path/code/config/.env" | grep -v ^# | xargs)
EOL EOL
chmod +x "$final_path/load_env" chmod +x "$final_path/code/load_env"
#================================================= #=================================================
# MIGRATE # MIGRATE
@ -166,10 +177,10 @@ chmod +x "$final_path/load_env"
( (
set +o nounset set +o nounset
source "${final_path}/virtualenv/bin/activate" source "${final_path}/code/virtualenv/bin/activate"
source "${final_path}/load_env" source "${final_path}/code/load_env"
set -o nounset set -o nounset
cd "$final_path" cd "$final_path/code"
# needed for enabling the 'unaccent' extension # needed for enabling the 'unaccent' extension
ynh_psql_execute_as_root "ALTER USER $db_user WITH SUPERUSER;" ynh_psql_execute_as_root "ALTER USER $db_user WITH SUPERUSER;"
@ -183,6 +194,7 @@ chmod +x "$final_path/load_env"
# https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16 #image-thumbnails-manual-action-required # https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16 #image-thumbnails-manual-action-required
python api/manage.py script create_image_variations --no-input python api/manage.py script create_image_variations --no-input
# https://docs.funkwhale.audio/upgrading/0.17.html#upgrade-instructions
python api/manage.py script migrate_to_user_libraries --no-input python api/manage.py script migrate_to_user_libraries --no-input
) )
@ -207,7 +219,7 @@ systemctl restart "$app".target
#================================================= #=================================================
chown -R "$app": "$final_path" chown -R "$app": "$final_path"
chmod -R 755 "$final_path/front/dist/" chmod -R 755 "$final_path/code/front/dist/"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT