From 034e5fc83c8515d2a7781548600ab82b44c8611b Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Feb 2019 00:39:19 +0100 Subject: [PATCH 1/7] Normalization from example_ynh --- README.md | 76 +++++++++++++++++++++++------------------- conf/nginx.conf | 8 +++-- manifest.json | 4 +-- scripts/backup | 14 ++++---- scripts/install | 23 ++++++------- scripts/restore | 14 ++++---- scripts/upgrade | 20 ++++++++--- sources/www/index.html | 4 +-- 8 files changed, 93 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index a37e805..4c8a501 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ -Custom Webapp -------------- +# Custom Webapp for YunoHost -Empty application with SFTP access to the Web directory. +[![Integration level](https://dash.yunohost.org/integration/my_webapp.svg)](https://dash.yunohost.org/appci/app/my_webapp) +[![Install Custom Webapp with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=my_webapp) + +> *This package allow you to install Custom Webapp quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* ## Overview @@ -17,49 +20,54 @@ at the installation. Under the Web directory, you will see a `www` folder which is the public and served one. You can put all the files of your custom Web application inside. -## Upgrade +**Shipped version:** 1.0 -Due to the SFTP access change, the upgrade can not be done from the last -`my_webapp` application - provided with YunoHost 2.2. You will have to remove -it first and install this new one, taking care of migrating your data. +## Screenshots -### Save your files and the database +## Demo -You will have to save the content of the `/var/www/my_webapp/files` -directory, either from the Web admin interface provided by the old app or -connecting to your server using SSH - or SFTP as `admin`. +## Configuration -If you've created a MySQL database, you can also migrate it since the new -version allows to manage it for you. To create a dump, you could either use -[phpMyAdmin](https://github.com/YunoHost-Apps/phpmyadmin_ynh) or connect to -your server and execute: -`mysqldump -u root -p$(cat /etc/yunohost/mysql --no-create-db "$dbname" > ./dump.sql` -(do not forget to replace `$dbname` by your database name). +## Documentation -### Restore your custom Webapp + * YunoHost documentation: https://github.com/YunoHost/doc/blob/master/app_my_webapp.md -When you've taken care of saving your files - and optionally your database, -you can remove the app and install this new one. You can set the same -settings as the previous installation. +## YunoHost specific features -To restore your files, connect to the Web directory using the SFTP account - as -described at the installation path - and put everything into the `www` directory. +#### Multi-users support -If you have chosen to migrate your database too, open the file `db_access.txt` -to know the new database, user and password you will have to set in your app -configuration. You can restore the dump you've created earlier either using -[phpMyAdmin](https://github.com/YunoHost-Apps/phpmyadmin_ynh) or connect to -your server and execute: -`mysql -u "$dbuser" -p"$dbpass" "$dbname" < ./dump.sql` -(do not forget to replace `$dbuser`, `$dbpass` and `$dbname` with the values -given in the file). +#### Supported architectures -### SFTP port ### +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/my_webapp/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/my_webapp/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/my_webapp/) + +## Limitations + +## Additional information + +#### SFTP port You may have change the SSH port as described [here (section "Modifier le port SSH"](https://yunohost.org/#/security_fr) ; then you should use this port to update your website with SFTP. -## Links +## Links -**YunoHost**: https://yunohost.org/ + * Report a bug: https://github.com/YunoHost-Apps/my_webapp_ynh/issues + * YunoHost website: https://yunohost.org/ + +--- + +Developers info +---------------- + +**Only if you want to use a testing branch for coding, instead of merging directly into master.** +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing --debug +or +sudo yunohost app upgrade my_webapp -u https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing --debug +``` diff --git a/conf/nginx.conf b/conf/nginx.conf index 2d343ab..6cbe641 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,10 @@ -location __PATH__ { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { + + # Path to source alias __FINALPATH__/www/; - + + # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } diff --git a/manifest.json b/manifest.json index 1152e2a..3268fdc 100644 --- a/manifest.json +++ b/manifest.json @@ -6,9 +6,9 @@ "en": "Custom Web app with SFTP access", "fr": "Application Web personnalisée avec accès SFTP" }, - "version": "1.0", + "version": "1.0~ynh1", "url": "https://github.com/YunoHost-Apps/my_webapp_ynh", - "license": "GPLv3", + "license": "GPL-3.0-only", "maintainer": { "name": "YunoHost Contributors", "email": "apps@yunohost.org" diff --git a/scripts/backup b/scripts/backup index 13b9193..7edc57f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -2,19 +2,19 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= 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 #================================================= diff --git a/scripts/install b/scripts/install index 9b32084..624655e 100644 --- a/scripts/install +++ b/scripts/install @@ -42,8 +42,6 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder" # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url @@ -89,14 +87,6 @@ ynh_system_user_exists "$user" || \ # Add the password to this user chpasswd <<< "${user}:${password}" -#================================================= -# PHP-FPM CONFIGURATION -#================================================= - -# Create a dedicated php-fpm config -ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" -ynh_add_fpm_config - #================================================= # SPECIFIC SETUP #================================================= @@ -120,8 +110,8 @@ systemctl reload ssh # FILL AND COPY SOURCE FILES #================================================= -ynh_replace_string "{DOMAIN}" "$domain" ../sources/www/index.html -ynh_replace_string "{USER}" "$user" ../sources/www/index.html +ynh_replace_string "__DOMAIN__" "$domain" ../sources/www/index.html +ynh_replace_string "__USER__" "$user" ../sources/www/index.html if [ $with_mysql -eq 1 ]; then # Store the database access @@ -132,6 +122,15 @@ fi # Copy files to the right place cp -r ../sources "$final_path" +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_print_info "Configuring php-fpm..." + +# Create a dedicated php-fpm config +ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" +ynh_add_fpm_config + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 6c5a219..980286c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -2,19 +2,19 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= 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 #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index abacad4..5f70cba 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -36,6 +36,15 @@ https://github.com/YunoHost-Apps/my_webapp_ynh#upgrade" # ENSURE DOWNWARD COMPATIBILITY #================================================= +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + # If db_name doesn't exist, create it if [ -z $db_name ]; then db_name=$(ynh_sanitize_dbid $app) @@ -52,11 +61,14 @@ fi # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_backup_before_upgrade # Backup the current version of the app +# Backup the current version of the app +ynh_backup_before_upgrade ynh_clean_setup () { - ynh_restore_upgradebackup # restore it if the upgrade fails + # restore it if the upgrade fails + ynh_restore_upgradebackup } -ynh_abort_if_errors # Exit if an error occurs during the execution of the script +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE PATH @@ -130,7 +142,7 @@ fi #================================================= # Remove the previous config for upgrading it -sudo sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config +sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config # Harden SSH connection for the user echo "##-> ${app} # Hardening user connection diff --git a/sources/www/index.html b/sources/www/index.html index cb0cf2f..051a429 100644 --- a/sources/www/index.html +++ b/sources/www/index.html @@ -16,11 +16,11 @@

Domain
-
{DOMAIN}
+
__DOMAIN__
Port
22 (or the port you defined if you change the ssh port)
User
-
{USER}
+
__USER__
Password
the one you set at installation
From 0f0bef3b8ca06d8f36f3de90c3502c529a6bc280 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Feb 2019 00:41:43 +0100 Subject: [PATCH 2/7] Use php7 --- conf/nginx.conf | 2 +- conf/php-fpm.conf | 104 +++++++++++++++++++++++++++++++--------------- manifest.json | 4 +- scripts/backup | 2 +- scripts/restore | 4 +- 5 files changed, 77 insertions(+), 39 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 6cbe641..566126f 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -32,7 +32,7 @@ location __PATH__/ { # Execute and serve PHP files location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 0327114..4447349 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -1,10 +1,11 @@ ; Start a new pool named 'www'. -; the variable $pool can we used in any directive and will be replaced by the +; the variable $pool can be used in any directive and will be replaced by the ; pool name ('www' here) [__NAMETOCHANGE__] ; Per pool prefix ; It only applies on the following directives: +; - 'access.log' ; - 'slowlog' ; - 'listen' (unixsocket) ; - 'chroot' @@ -24,28 +25,35 @@ group = __USER__ ; The address on which to accept FastCGI requests. ; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; +; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses +; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock -; Set listen(2) backlog. A value of '-1' means unlimited. -; Default Value: 128 (-1 on FreeBSD and OpenBSD) -;listen.backlog = 128 +; Set listen(2) backlog. +; Default Value: 511 (-1 on FreeBSD and OpenBSD) +;listen.backlog = 511 ; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. +; BSD-derived systems allow connections regardless of permissions. ; Default Values: user and group are set as the running user ; mode is set to 0660 listen.owner = www-data listen.group = www-data ;listen.mode = 0660 - -; List of ipv4 addresses of FastCGI clients which are allowed to connect. +; When POSIX Access Control Lists are supported you can set them using +; these options, value is a comma separated list of user/group names. +; When set, listen.owner and listen.group are ignored +;listen.acl_users = +;listen.acl_groups = + +; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address ; must be separated by a comma. If this value is left blank, connections will be @@ -59,7 +67,13 @@ listen.group = www-data ; - The pool processes will inherit the master process priority ; unless it specified otherwise ; Default Value: no set -; priority = -19 +; process.priority = -19 + +; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user +; or group is differrent than the master process user. It allows to create process +; core dump and ptrace the process for the pool user. +; Default Value: no +; process.dumpable = yes ; Choose how the process manager will control the number of child processes. ; Possible Values: @@ -96,7 +110,7 @@ pm = dynamic ; forget to tweak pm.* to fit your needs. ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' ; Note: This value is mandatory. -pm.max_children = 10 +pm.max_children = 5 ; The number of child processes created on startup. ; Note: Used only when pm is set to 'dynamic' @@ -117,12 +131,12 @@ pm.max_spare_servers = 3 ; Note: Used only when pm is set to 'ondemand' ; Default Value: 10s ;pm.process_idle_timeout = 10s; - + ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 -pm.max_requests = 500 +;pm.max_requests = 500 ; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. It shows the following informations: @@ -170,7 +184,7 @@ pm.max_requests = 500 ; ; By default the status page only outputs short status. Passing 'full' in the ; query string will also return status for each pool process. -; Example: +; Example: ; http://www.foo.bar/status?full ; http://www.foo.bar/status?json&full ; http://www.foo.bar/status?html&full @@ -215,7 +229,7 @@ pm.max_requests = 500 ; last request memory: 0 ; ; Note: There is a real-time FPM status monitoring sample web page available -; It's available in: ${prefix}/share/fpm/status.html +; It's available in: /usr/share/php/7.0/fpm/status.html ; ; Note: The value must start with a leading slash (/). The value can be ; anything, but it may not be a good idea to use the .php extension or it @@ -275,7 +289,7 @@ pm.max_requests = 500 ; - %{megabytes}M ; - %{mega}M ; %n: pool name -; %o: ouput header +; %o: output header ; it must be associated with embraces to specify the name of the header: ; - %{Content-Type}o ; - %{X-Powered-By}o @@ -283,7 +297,7 @@ pm.max_requests = 500 ; - .... ; %p: PID of the child that serviced the request ; %P: PID of the parent of the child that serviced the request -; %q: the query string +; %q: the query string ; %Q: the '?' character if query string exists ; %r: the request URI (without the query string, see %q and %Q) ; %R: remote IP address @@ -291,47 +305,51 @@ pm.max_requests = 500 ; %t: server time the request was received ; it can accept a strftime(3) format: ; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsuled in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t ; %T: time the log has been written (the request has finished) ; it can accept a strftime(3) format: ; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsuled in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t ; %u: remote user ; ; Default: "%R - %u %t \"%m %r\" %s" ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - + ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set -slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log - +;slowlog = log/$pool.log.slow + ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -request_slowlog_timeout = 5s - +;request_slowlog_timeout = 0 + ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 1d - + ; Set open file descriptor rlimit. ; Default Value: system defined value ;rlimit_files = 1024 - + ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value ;rlimit_core = 0 - + ; Chroot to this directory at the start. This value must be defined as an ; absolute path. When this value is not set, chroot is not used. ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one ; of its subdirectories. If the pool prefix is not set, the global prefix ; will be used instead. -; Note: chrooting is a great security feature and should be used whenever +; Note: chrooting is a great security feature and should be used whenever ; possible. However, all PHP paths will be relative to the chroot ; (error_log, sessions.save_path, ...). ; Default Value: not set @@ -347,16 +365,25 @@ chdir = __FINALPATH__ ; Note: on highloaded environement, this can cause some delay in the page ; process time (several ms). ; Default Value: no -catch_workers_output = yes +;catch_workers_output = yes + +; Clear environment in FPM workers +; Prevents arbitrary environment variables from reaching FPM worker processes +; by clearing the environment in workers before env vars specified in this +; pool configuration are added. +; Setting to "no" will make all environment variables available to PHP code +; via getenv(), $_ENV and $_SERVER. +; Default Value: yes +;clear_env = no ; Limits the extensions of the main script FPM will allow to parse. This can ; prevent configuration mistakes on the web server side. You should only limit ; FPM to .php extensions to prevent malicious users to use other extensions to -; exectute php code. +; execute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 - +;security.limit_extensions = .php .php3 .php4 .php5 .php7 + ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. ; Default Value: clean env @@ -370,7 +397,7 @@ catch_workers_output = yes ; overwrite the values previously defined in the php.ini. The directives are the ; same as the PHP SAPI: ; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. +; be overwritten from PHP call 'ini_set'. ; php_admin_value/php_admin_flag - these directives won't be overwritten by ; PHP call 'ini_set' ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. @@ -391,6 +418,17 @@ catch_workers_output = yes ;php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 32M +; Common values to change to increase file upload limit +; php_admin_value[upload_max_filesize] = 50M +; php_admin_value[post_max_size] = 50M +; php_admin_flag[mail.add_x_header] = Off + +; Other common parameters +; php_admin_value[max_execution_time] = 600 +; php_admin_value[max_input_time] = 300 +; php_admin_value[memory_limit] = 256M +; php_admin_flag[short_open_tag] = On + ; Additional php.ini defines, specific to this pool of workers. php_value[upload_max_filesize] = 1G php_value[post_max_size] = 1G diff --git a/manifest.json b/manifest.json index 3268fdc..c5d2d8e 100644 --- a/manifest.json +++ b/manifest.json @@ -14,12 +14,12 @@ "email": "apps@yunohost.org" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.0" }, "multi_instance": true, "services": [ "nginx", - "php5-fpm" + "php7.0-fpm" ], "arguments": { "install" : [ diff --git a/scripts/backup b/scripts/backup index 7edc57f..b0eedbe 100644 --- a/scripts/backup +++ b/scripts/backup @@ -44,7 +44,7 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE diff --git a/scripts/restore b/scripts/restore index 980286c..8822a76 100644 --- a/scripts/restore +++ b/scripts/restore @@ -86,7 +86,7 @@ chown root: "$final_path" # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" +ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION @@ -113,5 +113,5 @@ systemctl reload ssh # RELOAD NGINX AND PHP-FPM #================================================= -systemctl reload php5-fpm +systemctl reload php7.0-fpm systemctl reload nginx From 6fa397587f6edd2ac311e9961ea4ff2705b00d60 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Feb 2019 00:44:14 +0100 Subject: [PATCH 3/7] Give up upgrade from very old version --- scripts/upgrade | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 5f70cba..91fd49f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,15 +23,6 @@ with_mysql=$(ynh_app_setting_get $app with_mysql) password=$(ynh_app_setting_get $app password) user=$(ynh_app_setting_get $app user) -#================================================= -# CHECK IF THE UPGRADE CAN BE AUTOMATED -#================================================= - -([[ -n "$with_mysql" ]] && [[ -n "$password" ]] && [[ -n "$user" ]]) \ - || ynh_die "The app changed and can not be automatically upgraded. \ -You will have to manually upgrade it following these instructions: \ -https://github.com/YunoHost-Apps/my_webapp_ynh#upgrade" - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= From d5e9add734927395d48bd449b99ac81bd91dd009 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Feb 2019 00:45:30 +0100 Subject: [PATCH 4/7] Use ynh_backup_if_checksum_is_different instead of a dedicated function --- scripts/upgrade | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 91fd49f..d042ba2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -70,32 +70,13 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS -#================================================= - -# Check if a config file was modified -is_checksum_different () { - local file=$1 - local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' - local checksum_value=$(ynh_app_setting_get $app $checksum_setting_name) - if [ -n "$checksum_value" ] - then # Proceed only if a value was stored into the app settings - if ! echo "$checksum_value $file" | sudo md5sum -c --status - then # If the checksum is now different - echo "File $file has been manually modified since the installation or last upgrade. So it will not be replaced." >&2 - echo "1" - else - echo "0" - fi - else - echo "0" - fi -} - #================================================= # NGINX CONFIGURATION #================================================= -if [ $(is_checksum_different "/etc/nginx/conf.d/$domain.d/$app.conf") -eq 0 ] +modified_config=$(ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf") +# Replace nginx config only if it wasn't modified. +if [ -z "$modified_config" ] then # Create a dedicated nginx config ynh_add_nginx_config @@ -119,7 +100,9 @@ usermod -g "$user" "$user" # PHP-FPM CONFIGURATION #================================================= -if [ $(is_checksum_different "/etc/php5/fpm/pool.d/$app.conf") -eq 0 ] +modified_config=$(ynh_backup_if_checksum_is_different "/etc/php5/fpm/pool.d/$app.conf") +# Replace nginx config only if it wasn't modified. +if [ -z "$modified_config" ] then # Create a dedicated php-fpm config ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" From 8c2f9fa5c7a6ab90ebbbee4eb4b82ed2be6ee292 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 17 Feb 2019 20:55:53 +0100 Subject: [PATCH 5/7] Add progression with ynh_print_info --- scripts/backup | 11 +++++++++++ scripts/install | 14 ++++++++++++++ scripts/remove | 14 ++++++++++++++ scripts/restore | 13 +++++++++++++ scripts/upgrade | 15 +++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/scripts/backup b/scripts/backup index b0eedbe..021bb79 100644 --- a/scripts/backup +++ b/scripts/backup @@ -18,6 +18,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -31,18 +32,21 @@ with_mysql=$(ynh_app_setting_get $app with_mysql) #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_print_info "Backing up the main app directory..." ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_print_info "Backing up nginx web server configuration..." ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Backing up php-fpm configuration..." ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" @@ -51,5 +55,12 @@ ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= if [ $with_mysql -eq 1 ]; then + ynh_print_info "Backing up the MySQL database..." ynh_mysql_dump_db "$db_name" > db.sql fi + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 624655e..f4952f6 100644 --- a/scripts/install +++ b/scripts/install @@ -31,6 +31,7 @@ app_nb=$YNH_APP_INSTANCE_NUMBER #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -48,6 +49,7 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." user=webapp${app_nb} ynh_app_setting_set $app domain $domain @@ -65,6 +67,7 @@ ynh_app_setting_set $app final_path $final_path #================================================= if [ $with_mysql -eq 1 ]; then + ynh_print_info "Creating a MySQL database..." db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name ynh_mysql_setup_db $db_name $db_name @@ -73,6 +76,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config @@ -80,6 +84,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Configuring system user..." # Create a standard user (not a system user for sftp) ynh_system_user_exists "$user" || \ @@ -92,6 +97,7 @@ chpasswd <<< "${user}:${password}" #================================================= # CONFIGURE SSH #================================================= +ynh_print_info "Configuring ssh..." # Harden SSH connection for the user echo "##-> ${app} @@ -146,6 +152,7 @@ chown root: "$final_path" #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -156,5 +163,12 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 83e2ef3..c909ea9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,6 +11,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -27,6 +28,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= if [ $with_mysql -eq 1 ]; then + ynh_print_info "Removing the MySQL database" # Remove a database if it exists, along with the associated user ynh_mysql_remove_db $db_name $db_name fi @@ -34,6 +36,7 @@ fi #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -41,6 +44,8 @@ ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" + # Remove the dedicated nginx config ynh_remove_nginx_config @@ -48,6 +53,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Removing php-fpm configuration" # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -57,6 +63,7 @@ ynh_remove_fpm_config #================================================= # REMOVE THE CUSTOM SSH CONFIG #================================================= +ynh_print_info "Removing the custom ssh config" sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config systemctl reload ssh @@ -66,6 +73,13 @@ systemctl reload ssh #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" # Delete an user ynh_system_user_delete $user + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 8822a76..efb77e8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -18,6 +18,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -32,6 +33,7 @@ user=$(ynh_app_setting_get $app user) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_print_info "Validating restoration parameters..." ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -49,6 +51,7 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_print_info "Restoring the app main directory..." ynh_restore_file "$final_path" @@ -57,6 +60,7 @@ ynh_restore_file "$final_path" #================================================= if [ $with_mysql -eq 1 ]; then + ynh_print_info "Restoring the mysql database..." db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $db_name $db_name $db_pwd ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql @@ -65,6 +69,7 @@ fi #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Recreating the dedicated system user..." # Create a standard user (not a system user for sftp) ynh_system_user_exists "$user" || \ @@ -93,6 +98,7 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # CONFIGURE SSH #================================================= +ynh_print_info "Configuring ssh..." # Harden SSH connection for the user echo "##-> ${app} @@ -112,6 +118,13 @@ systemctl reload ssh #================================================= # RELOAD NGINX AND PHP-FPM #================================================= +ynh_print_info "Reloading nginx web server and php-fpm..." systemctl reload php7.0-fpm systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index d042ba2..4a7912f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,6 +11,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -26,6 +27,7 @@ user=$(ynh_app_setting_get $app user) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_print_info "Ensuring downward compatibility..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then @@ -51,6 +53,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -78,6 +81,7 @@ modified_config=$(ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain # Replace nginx config only if it wasn't modified. if [ -z "$modified_config" ] then + ynh_print_info "Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config fi @@ -85,6 +89,7 @@ fi #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." # Create a standard user (not a system user for sftp) ynh_system_user_exists "$user" || \ @@ -104,6 +109,7 @@ modified_config=$(ynh_backup_if_checksum_is_different "/etc/php5/fpm/pool.d/$app # Replace nginx config only if it wasn't modified. if [ -z "$modified_config" ] then + ynh_print_info "Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" ynh_add_fpm_config @@ -114,6 +120,7 @@ fi #================================================= # CONFIGURE SSH #================================================= +ynh_print_info "Configuring ssh..." # Remove the previous config for upgrading it sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config @@ -143,6 +150,7 @@ chown root: "$final_path" #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -153,5 +161,12 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed" From 7bae826582232a703e7cc68c26d92372873f189e Mon Sep 17 00:00:00 2001 From: Kayou Date: Tue, 19 Mar 2019 19:32:57 +0100 Subject: [PATCH 6/7] Remove unnecessary comments --- scripts/change_url | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index f71fc77..a4eed15 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -28,10 +28,6 @@ app=$YNH_APP_INSTANCE_NAME # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get $app final_path) -# Add settings here as needed by your application -#db_name=$(ynh_app_setting_get "$app" db_name) -#db_pwd=$(ynh_app_setting_get $app db_pwd) - #================================================= # CHECK THE SYNTAX OF THE PATHS #================================================= @@ -87,12 +83,6 @@ then ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -# ... -#================================================= - #================================================= # GENERIC FINALISATION #================================================= From 4f37db1582f79a3d57a8d0a2f598dcea55a09521 Mon Sep 17 00:00:00 2001 From: Kayou Date: Tue, 19 Mar 2019 19:34:21 +0100 Subject: [PATCH 7/7] Bump version number --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c5d2d8e..a62df13 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "apps@yunohost.org" }, "requirements": { - "yunohost": ">= 3.0" + "yunohost": ">= 3.2.0" }, "multi_instance": true, "services": [