diff --git a/check_process b/check_process index 4046c3d..6d0f1f5 100644 --- a/check_process +++ b/check_process @@ -28,8 +28,6 @@ upgrade=1 from_commit=cba843be0d7e00d7d7290f0d0da95807711a96d4 # 1.1.0~ynh1 upgrade=1 from_commit=5780e424cf3217bf9d25e5b24beb51f52b6b777e - # 1.1.0~ynh1 - upgrade=1 from_commit=5780e424cf3217bf9d25e5b24beb51f52b6b777e backup_restore=1 multi_instance=1 port_already_use=0 @@ -52,5 +50,3 @@ Notification=all name=1.0.7~ynh1 ; commit=5780e424cf3217bf9d25e5b24beb51f52b6b777e name=1.1.0~ynh1 - ; commit=5780e424cf3217bf9d25e5b24beb51f52b6b777e - name=1.1.0~ynh1 diff --git a/conf/uploads.exs b/conf/uploads.exs new file mode 100644 index 0000000..5b15f28 --- /dev/null +++ b/conf/uploads.exs @@ -0,0 +1,2 @@ + +config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "__DATADIR__/uploads" diff --git a/scripts/backup b/scripts/backup index 77494ff..e637692 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=db_name) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -56,6 +57,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="$datadir" --is_big + #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/change_url b/scripts/change_url index 959d77c..c663812 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -122,7 +122,7 @@ ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" - ynh_store_file_checksum --file="$config" chmod 400 "$config" -chown $app:www-data "$config" +chown $app:$app "$config" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 826cfc0..d66b0ca 100644 --- a/scripts/install +++ b/scripts/install @@ -133,6 +133,24 @@ ynh_add_nginx_config #================================================= # SPECIFIC SETUP +#================================================= +# CREATE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Creating the data directory..." + +# Define app's data directory +datadir="/home/yunohost.app/${app}" + +ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + +# Create app folders +mkdir -p "$datadir/" +mkdir -p "$datadir/uploads/" + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:$app "$datadir" + #================================================= # MAKE SETUP #================================================= @@ -148,6 +166,8 @@ pushd $final_path/$app/js sudo -u $app env PATH=$PATH NODE_BUILD_MEMORY=1024 yarn run build popd +ynh_secure_remove --file="$final_path/$app/js" + ynh_script_progression --message="Building Elixir application (this is going to take a while...)" pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix local.hex --force @@ -159,6 +179,8 @@ popd cat "../conf/ldap.exs" >> "$config" cat "../conf/mail.exs" >> "$config" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="../conf/uploads.exs" +cat "../conf/uploads.exs" >> "$config" pushd $final_path/$app chmod o-rwx $config @@ -174,10 +196,12 @@ pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix mobilizon.users.new "$admin_email" --admin --password "$password" popd +ynh_secure_remove --file="$final_path/.cache" + ynh_store_file_checksum --file="$config" chmod 400 "$config" -chown $app:www-data "$config" +chown $app:$app "$config" #================================================= # SETUP SYSTEMD diff --git a/scripts/restore b/scripts/restore index 8f1db57..147bb5d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -36,6 +36,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) port=$(ynh_app_setting_get --app=$app --key=port) ynh_user_password=$(ynh_app_setting_get --app=$app --key=ynh_user_password) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -80,6 +81,22 @@ chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION +#================================================= +# RECREATE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Recreating the data directory..." + +# 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 + +# Create app folders +mkdir -p "$datadir/" +mkdir -p "$datadir/uploads/" + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:$app "$datadir" + #================================================= # REINSTALL DEPENDENCIES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index dd4c35a..4604a14 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,6 +28,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) port=$(ynh_app_setting_get --app=$app --key=port) secret=$(ynh_app_setting_get --app=$app --key=secret) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK VERSION @@ -126,6 +127,44 @@ ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" +#================================================= +# CREATE DATADIR FOLDER +#================================================= + +# If datadir doesn't exist, create it +if [ -z "$datadir" ]; then + ynh_script_progression --message="Create datadir folder..." + + # Define app's data directory + datadir="/home/yunohost.app/${app}" + + ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + + # Create app folders + mkdir -p "$datadir/" + mkdir -p "$datadir/uploads/" + + chmod 750 "$datadir" + chmod -R o-rwx "$datadir" + chown -R $app:$app "$datadir" + + rsync -a $final_path/$app/uploads/ $datadir/uploads/ + + config="$final_path/$app/config/prod.secret.exs" + + ynh_backup_if_checksum_is_different --file="$config" + + ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="../conf/uploads.exs" + cat "../conf/uploads.exs" >> "$config" + + ynh_store_file_checksum --file="$config" + + chmod 400 "$config" + chown $app:$app "$config" + + ynh_secure_remove --file="$final_path/$app/uploads" +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -140,9 +179,6 @@ then # Backup the config file in the temp dir cp -af "$final_path/$app/config/prod.secret.exs" "$tmpdir/prod.secret.exs" - # Backup upload dir - rsync -a "$final_path/$app/uploads" "$tmpdir/." - # Remove the app directory securely ynh_secure_remove --file="$final_path/$app" @@ -152,9 +188,6 @@ then # Restore the config file cp -af "$tmpdir/prod.secret.exs" "$final_path/$app/config/prod.secret.exs" - # Restore upload dir - rsync -a "$tmpdir/uploads" "$final_path/$app/." - # Remove the tmp directory securely ynh_secure_remove --file="$tmpdir" fi @@ -196,8 +229,11 @@ pushd $final_path/$app/js sudo -u $app env PATH=$PATH yarn install ynh_script_progression --message="Building NodeJS application (this is going to take a while...)" sudo -u $app env PATH=$PATH NODE_BUILD_MEMORY=1024 yarn run build + sudo -u $app env PATH=$PATH yarn cache clean --all popd +ynh_secure_remove --file="$final_path/$app/js" + ynh_script_progression --message="Building Elixir application (this is going to take a while...)" pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix local.hex --force @@ -207,6 +243,8 @@ pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix ecto.migrate popd +ynh_secure_remove --file="$final_path/.cache" + #================================================= # RUN APP MIGRATIONS #================================================= @@ -229,7 +267,7 @@ ynh_backup_if_checksum_is_different --file="$config" ynh_store_file_checksum --file="$config" chmod 400 "$config" -chown $app:www-data "$config" +chown $app:$app "$config" #================================================= # SETUP SYSTEMD