From 11bd9c69a68084e3e6dbd49f37cb184e4093f84f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 23 Apr 2021 21:17:00 +0200 Subject: [PATCH 1/9] Fix upload --- conf/uploads.exs | 2 ++ scripts/backup | 9 +++++++++ scripts/change_url | 2 +- scripts/install | 22 +++++++++++++++++++++- scripts/restore | 17 +++++++++++++++++ scripts/upgrade | 37 ++++++++++++++++++++++++++++++++++++- 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 conf/uploads.exs diff --git a/conf/uploads.exs b/conf/uploads.exs new file mode 100644 index 0000000..2e24754 --- /dev/null +++ b/conf/uploads.exs @@ -0,0 +1,2 @@ + +config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "__DATADIR__/uploads" \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 77494ff..c4f472b 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,14 @@ 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="/etc/$app/config.exs" + +ynh_backup --src_path="$datadir" --is_big + #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/change_url b/scripts/change_url index d4b8f51..708ede5 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..66b7c6c 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 #================================================= @@ -159,6 +177,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 @@ -177,7 +197,7 @@ popd 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..113da70 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 @@ -118,6 +119,40 @@ if ynh_version_gt "1.0.0~ynh1" "${previous_version}" ; then ynh_store_file_checksum --file="$config" fi +#================================================= +# 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" + + 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" +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -229,7 +264,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 From 0d6fdce7ee11b6f8956209ac002ea566dfca53fd Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 23 Apr 2021 21:20:36 +0200 Subject: [PATCH 2/9] Update uploads.exs --- conf/uploads.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/uploads.exs b/conf/uploads.exs index 2e24754..5b15f28 100644 --- a/conf/uploads.exs +++ b/conf/uploads.exs @@ -1,2 +1,2 @@ -config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "__DATADIR__/uploads" \ No newline at end of file +config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "__DATADIR__/uploads" From 965ac3d21ddeb494727ea889fd65a9af059bb22e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 24 Apr 2021 13:14:31 +0200 Subject: [PATCH 3/9] Fix backup --- scripts/backup | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index c4f472b..e637692 100644 --- a/scripts/backup +++ b/scripts/backup @@ -61,8 +61,6 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/$app/config.exs" - ynh_backup --src_path="$datadir" --is_big #================================================= From 4c50647173eeba71164e08c906526aaf9eb626d3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 25 Apr 2021 19:19:22 +0200 Subject: [PATCH 4/9] Move uploads files --- scripts/upgrade | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 113da70..b83f87a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -119,6 +119,14 @@ if ynh_version_gt "1.0.0~ynh1" "${previous_version}" ; then ynh_store_file_checksum --file="$config" fi +#================================================= +# CREATE DEDICATED USER +#================================================= +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 #================================================= @@ -140,6 +148,8 @@ if [ -z "$datadir" ]; then 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" @@ -151,16 +161,10 @@ if [ -z "$datadir" ]; then chmod 400 "$config" chown $app:$app "$config" + + ynh_secure_remove --file="$final_path/$app/uploads" fi -#================================================= -# CREATE DEDICATED USER -#================================================= -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" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= From 87eb2325c966603849cc1e92397d9e7832da6f3c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 26 Apr 2021 20:01:52 +0200 Subject: [PATCH 5/9] Fix rsync --- scripts/upgrade | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index b83f87a..f5ff16f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -148,7 +148,9 @@ if [ -z "$datadir" ]; then chmod -R o-rwx "$datadir" chown -R $app:$app "$datadir" - rsync -a $final_path/$app/uploads/ $datadir/uploads/ + if [ -d "$final_path/$app/uploads/" ]; then + rsync -a $final_path/$app/uploads/ $datadir/uploads/ + fi config="$final_path/$app/config/prod.secret.exs" From b4052f3a5703c1632ecd4b58248531617f1e4fba Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 27 Apr 2021 17:55:17 +0200 Subject: [PATCH 6/9] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index f5ff16f..f87603d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -148,7 +148,7 @@ if [ -z "$datadir" ]; then chmod -R o-rwx "$datadir" chown -R $app:$app "$datadir" - if [ -d "$final_path/$app/uploads/" ]; then + if [[ -d "$final_path/$app/uploads/" ]]; then rsync -a $final_path/$app/uploads/ $datadir/uploads/ fi From 74dc992fce0b45e433151bfb914d78f78a589816 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 27 Apr 2021 22:56:03 +0200 Subject: [PATCH 7/9] Fix upgrade steps --- check_process | 4 ---- scripts/upgrade | 10 +--------- 2 files changed, 1 insertion(+), 13 deletions(-) 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/scripts/upgrade b/scripts/upgrade index f87603d..1f09fe5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -148,9 +148,7 @@ if [ -z "$datadir" ]; then chmod -R o-rwx "$datadir" chown -R $app:$app "$datadir" - if [[ -d "$final_path/$app/uploads/" ]]; then - rsync -a $final_path/$app/uploads/ $datadir/uploads/ - fi + rsync -a $final_path/$app/uploads/ $datadir/uploads/ config="$final_path/$app/config/prod.secret.exs" @@ -181,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" @@ -193,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 From a71f177219a3d8d54138808acdb33cb932c51e15 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 27 Apr 2021 23:58:57 +0200 Subject: [PATCH 8/9] cleanup cache --- scripts/install | 2 ++ scripts/upgrade | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/install b/scripts/install index 66b7c6c..b8715ed 100644 --- a/scripts/install +++ b/scripts/install @@ -199,6 +199,8 @@ ynh_store_file_checksum --file="$config" chmod 400 "$config" chown $app:$app "$config" +ynh_secure_remove --file="$final_path/.cache" + #================================================= # SETUP SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1f09fe5..2afb2b5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -264,6 +264,8 @@ ynh_store_file_checksum --file="$config" chmod 400 "$config" chown $app:$app "$config" +ynh_secure_remove --file="$final_path/.cache" + #================================================= # SETUP SYSTEMD #================================================= From 8ea9b947babf6a7f278e2f6c1b1603eaf25a778f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 28 Apr 2021 02:05:01 +0200 Subject: [PATCH 9/9] Cleanup --- scripts/install | 6 ++++-- scripts/upgrade | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index b8715ed..d66b0ca 100644 --- a/scripts/install +++ b/scripts/install @@ -166,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 @@ -194,13 +196,13 @@ 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:$app "$config" -ynh_secure_remove --file="$final_path/.cache" - #================================================= # SETUP SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2afb2b5..4604a14 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -229,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 @@ -240,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 #================================================= @@ -264,8 +269,6 @@ ynh_store_file_checksum --file="$config" chmod 400 "$config" chown $app:$app "$config" -ynh_secure_remove --file="$final_path/.cache" - #================================================= # SETUP SYSTEMD #=================================================