diff --git a/conf/message_remove b/conf/message_remove index a7126dc..367704b 100644 --- a/conf/message_remove +++ b/conf/message_remove @@ -3,12 +3,12 @@ __APP__ was successfully removed :) __APP__ was successfully removed. The domain https://__DOMAIN____PATH_URL__ is free for other apps to be installed on it. But a futher action is required from your side to completely remove the __APP__ data folder. If you have backup and plan to restore this app in the future DON'T RUN THIS COMMAND. -And if you are going to migrate to othe server you will have to move /home/yunohost.app/__APP__ to your new server. +And if you are going to migrate to othe server you will have to move __DATADIR__ to your new server. You need to run this command to remove the data (warning all your videos will be removed): -rm -R /home/yunohost.app/__APP__ -f +rm -R __DATADIR__ -f If you facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 719ebe8..f0306bb 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -26,7 +26,7 @@ location ~ ^/static/(thumbnails|avatars)/ { # Cache 2 hours more_set_headers "Cache-Control : public, max-age=7200"; - root /home/yunohost.app/__NAME__/storage; + root __DATADIR__; rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break; try_files $uri /; @@ -97,7 +97,7 @@ location ~ ^/static/(webseed|redundancy|streaming-playlists)/ { access_log off; } - root /home/yunohost.app/__NAME__/storage; + root __DATADIR__; rewrite ^/static/webseed/(.*)$ /videos/$1 break; rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; diff --git a/conf/production.yaml b/conf/production.yaml index 5dab156..6cccd20 100644 --- a/conf/production.yaml +++ b/conf/production.yaml @@ -70,18 +70,18 @@ email: # From the project root directory storage: - tmp: '/home/yunohost.app/__APP__/storage/tmp/' # Use to download data (imports etc), store uploaded files before processing... - avatars: '/home/yunohost.app/__APP__/storage/avatars/' - videos: '/home/yunohost.app/__APP__/storage/videos/' - streaming_playlists: '/home/yunohost.app/__APP__/storage/streaming-playlists/' - redundancy: '/home/yunohost.app/__APP__/storage/videos/' - logs: '/home/yunohost.app/__APP__/storage/logs/' - previews: '/home/yunohost.app/__APP__/storage/previews/' - thumbnails: '/home/yunohost.app/__APP__/storage/thumbnails/' - torrents: '/home/yunohost.app/__APP__/storage/torrents/' - captions: '/home/yunohost.app/__APP__/storage/captions/' - cache: '/home/yunohost.app/__APP__/storage/cache/' - plugins: '/home/yunohost.app/__APP__/storage/plugins/' + tmp: '__DATADIR__/tmp/' # Use to download data (imports etc), store uploaded files before processing... + avatars: '__DATADIR__/avatars/' + videos: '__DATADIR__/videos/' + streaming_playlists: '__DATADIR__/streaming-playlists/' + redundancy: '__DATADIR__/videos/' + logs: '__DATADIR__/logs/' + previews: '__DATADIR__/previews/' + thumbnails: '__DATADIR__/thumbnails/' + torrents: '__DATADIR__/torrents/' + captions: '__DATADIR__/captions/' + cache: '__DATADIR__/cache/' + plugins: '__DATADIR__/plugins/' log: level: 'info' # debug/info/warning/error diff --git a/scripts/backup b/scripts/backup index 65a1d11..7837123 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -69,6 +70,13 @@ ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql +#================================================= +# BACKUP THE DATA DIRECTORY +#================================================= +ynh_print_info --message="Backing up data directory..." + +ynh_backup --src_path="$datadir" --is_big + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 51a86c6..610549e 100644 --- a/scripts/install +++ b/scripts/install @@ -32,6 +32,9 @@ is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME +# Define app's data directory +datadir="/home/yunohost.app/${app}/storage" + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -52,6 +55,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email ynh_app_setting_set --app=$app --key=admin_pass --value=$admin_pass ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=datadir --value=$datadir #================================================= # STANDARD MODIFICATIONS @@ -115,8 +119,8 @@ ynh_setup_source --dest_dir="$final_path" #================================================= ynh_script_progression --message="Configuring NGINX web server..." -# Create a dedicated NGINX config -ynh_add_nginx_config +# Create a dedicated nginx config +ynh_add_nginx_config "datadir" #================================================= # CREATE DEDICATED USER @@ -133,9 +137,6 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= ynh_script_progression --message="Creating the data directory..." -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" - # Create app folders mkdir -p "$datadir" @@ -155,6 +156,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config" #Create the admin settings file local_config="$final_path/config/local-production.json" @@ -205,14 +207,14 @@ chown -R $app:$app $final_path ynh_script_progression --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="/home/yunohost.app/${app}/storage/logs/peertube.log" +ynh_use_logrotate --logfile="$datadir/logs/peertube.log" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" +yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 6fc38a1..f99235d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -23,6 +23,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_user=$app final_path=$(ynh_app_setting_get --app=$app --key=final_path) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -115,6 +116,7 @@ ynh_script_progression --message="Sending a readme for the admin..." ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/message_remove" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message_remove" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message_remove" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="../conf/message_remove" ynh_send_readme_to_admin --app_message="../conf/message_remove" --recipients=$admin_email --type='remove' diff --git a/scripts/restore b/scripts/restore index 7bcceb3..26195e7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -34,6 +34,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_user=$app db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -80,18 +81,14 @@ chown -R $app:$app $final_path #================================================= # SPECIFIC RESTORATION #================================================= -# CREATE THE DATA DIRECTORY +# RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Creating the data directory..." +ynh_script_progression --message="Restoring data directory..." -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" +# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. +ynh_restore_file --origin_path="$datadir" --not_mandatory -if [ ! -d "$datadir" ] -then - # Create app folders - mkdir -p "$datadir" -fi +mkdir -p "$datadir" # Give permission to the datadir chown -R "$app":"$app" "$datadir" @@ -139,7 +136,7 @@ systemctl enable $app.service #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" +yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 328bb82..c16f112 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK VERSION @@ -46,6 +47,12 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi +if [ -z "$datadir" ]; +then + datadir="/home/yunohost.app/${app}/storage" + ynh_app_setting_set --app=$app --key=datadir --value=$datadir +fi + # Close a port if yunohost firewall list | grep -q "\- $port$" then @@ -66,8 +73,16 @@ ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list" #================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." +# Inform the backup/restore process that it should not save the data directory +# Use only for the previous backup script that doesn't set 'is_big' +ynh_app_setting_set --app=$app --key=backup_core_only --value=1 + # Backup the current version of the app ynh_backup_before_upgrade + +# Remove the option backup_core_only after the backup. +ynh_app_setting_delete --app=$app --key=backup_core_only + ynh_clean_setup () { # restore it if the upgrade fails ynh_clean_check_starting @@ -128,8 +143,8 @@ fi #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." -# Create a dedicated NGINX config -ynh_add_nginx_config +# Create a dedicated nginx config +ynh_add_nginx_config "datadir" #================================================= # UPGRADE DEPENDENCIES @@ -171,9 +186,6 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Creating the data directory..." -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" - if [ ! -d "$datadir" ] then # Create app folders @@ -197,6 +209,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config" ynh_store_file_checksum --file="$config" local_config="$final_path/config/local-production.json"