diff --git a/scripts/backup b/scripts/backup index 3e329b9..1ea97b7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -2,13 +2,6 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,6 +14,13 @@ fi source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= @@ -30,11 +30,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -# The parameter $1 is the backup directory location which will be compressed afterward -backup_dir=$1/apps/container-$app -sudo mkdir -p $backup_dir #================================================= # STANDARD BACKUP STEPS @@ -42,23 +38,29 @@ sudo mkdir -p $backup_dir # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" "${backup_dir}/$final_path" +ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= ynh_mysql_dump_db "$db_name" > db.sql -ynh_backup "db.sql" "${backup_dir}/db.sql" + +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup "/etc/php/7.1/fpm/pool.d/$app.conf" +ynh_backup "/etc/php/7.1/fpm/conf.d/20-$app.ini" #================================================= # BACKUP THE CRON FILE #================================================= -ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app" +ynh_backup "/etc/cron.d/$app" diff --git a/scripts/install b/scripts/install index a68a64b..af5a630 100755 --- a/scripts/install +++ b/scripts/install @@ -145,9 +145,8 @@ cd $final_path && sudo /usr/bin/php7.1 artisan -q setup:production --force # create a cronjob to run the scheduler -echo "* * * * * sudo $app /usr/bin/php7.1 $final_path/artisan schedule:run" > /tmp/cron$app +echo "* * * * * -u $app /usr/bin/php7.1 $final_path/artisan schedule:run" > /tmp/cron$app sudo mv /tmp/cron$app /etc/cron.d/$app -sudo chown root /etc/cron.d/$app #================================================= # GENERIC FINALIZATION @@ -158,6 +157,13 @@ sudo chown root /etc/cron.d/$app # Set permissions to app files chown -R $app: $final_path +#================================================= +# STORE THE CHECKSUM OF THE CONFIG FILE +#================================================= + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/.env" + #================================================= # SETUP SSOWAT #================================================= @@ -176,5 +182,5 @@ fi #================================================= # RELOAD NGINX #================================================= - +systemctl reload php7.1-fpm systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index 62576d8..5f3e31b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get $app final_path) #================================================= # STANDARD REMOVE @@ -32,14 +34,14 @@ ynh_remove_app_dependencies #================================================= # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_name $db_name +ynh_mysql_remove_db $db_user $db_name #================================================= # REMOVE APP MAIN DIR #================================================= # Remove the app directory securely -ynh_secure_remove "/var/www/$app" +ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 2432870..a952019 100755 --- a/scripts/restore +++ b/scripts/restore @@ -2,22 +2,6 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= - -yunohost app checkurl "${domain}${path_url}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -30,6 +14,13 @@ fi source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= @@ -41,8 +32,25 @@ path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + #================================================= # STANDARD RESTORATION STEPS +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +ynh_install_php7 +ynh_install_nodejs 9 + #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= @@ -76,24 +84,18 @@ ynh_system_user_create $app # REINSTALL DEPENDENCIES #================================================= -ynh_install_php7 -ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath - -ynh_install_nodejs 6.10.3 - init_composer $final_path -cd $final_path && sudo_path npm install -g npm@4 pnpm -cd $final_path && sudo_path pnpm install -cd $final_path && sudo_path pnpm install -g bower gulp -cd $final_path && sudo_path bower install -f --allow-root +# Run migration +cd $final_path && sudo /usr/bin/php7.1 artisan migrate --force + #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files -chown -R www-data: $final_path +chown -R $app: $final_path #================================================= # RESTORE THE CRON FILE @@ -107,5 +109,5 @@ ynh_restore_file "/etc/cron.d/$app" # RELOAD NGINX AND PHP-FPM #================================================= -systemctl reload php5-fpm +systemctl reload php7.1-fpm systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index a2b262c..b8af7b5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,13 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # LOAD SETTINGS #================================================= @@ -45,6 +38,18 @@ if [ -z $db_name ]; then # If db_name doesn't exist, create it db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name fi +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE PATH @@ -58,9 +63,15 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= - +# Create a temporary directory +tmpdir="$(mktemp -d)" +cp -a "$final_path/.env" "$tmpdir/.env" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" +cp -a "$tmpdir/.env" "$final_path/.env" +#remove tmp dir +sudo rm -Rf "$tmpdir" + #================================================= # NGINX CONFIGURATION @@ -80,8 +91,6 @@ ynh_system_user_create $app #================================================= # SPECIFIC UPGRADE #================================================= -# ... -#================================================= # install new dependencies ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath @@ -93,24 +102,6 @@ ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xm # Create a dedicated php-fpm7.1 config ynh_add_fpm7.1_config - -# create a user -email=$(ynh_user_get_info $admin 'mail') - -# setup application config -sudo cp ../conf/.env $final_path/.env - -db_name=$(ynh_sanitize_dbid $app) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -sudo sed -i "s/yunouser/$db_name/g" $final_path/.env -sudo sed -i "s/yunopass/$db_pwd/g" $final_path/.env -sudo sed -i "s/yunobase/$db_name/g" $final_path/.env -sudo sed -i "s/yunomail/$email/g" $final_path/.env -sudo sed -i "s/yunodomain/$domain/g" $final_path/.env -sudo sed -i "s/language/$language/g" $final_path/.env - -exec_composer "$final_path" update --quiet --no-dev --prefer-dist - # setup application config cd $final_path && sudo /usr/bin/php7.1 artisan migrate --force