From f3696978387c6c92005c9744819159fc6cacb488 Mon Sep 17 00:00:00 2001 From: Gofannon <17145502+Gofannon@users.noreply.github.com> Date: Fri, 26 Aug 2022 19:42:56 +0200 Subject: [PATCH] enh php usage in the example 1. add "extra_php-fpm.conf" 2. harmonize "ynh_add_fpm_config" by using "fpm_footprint" variables --- scripts/install | 21 +++++++++++++++++++-- scripts/restore | 3 +++ scripts/upgrade | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 432ae5a..e0fbddf 100755 --- a/scripts/install +++ b/scripts/install @@ -170,7 +170,9 @@ ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 ### `ynh_add_fpm_config` is used to set up a PHP config. ### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf +### `ynh_add_fpm_config` will create a 'config' then add 'extra_php-fpm.conf' +### It can use be overwritten by 'conf/php-fpm.conf' but not by default +### See helper code https://github.com/YunoHost/yunohost/blob/dev/helpers/php ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script @@ -178,9 +180,24 @@ ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 ### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script ### with the reload at the end of the script. ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script +### - and references to 'fpm_footprint' and 'fpm_usage' in the upgrade script +### in sections "LOAD SETTINGS" and "ENSURE DOWNWARD COMPATIBILITY" # Create a dedicated PHP-FPM config -ynh_add_fpm_config +# default setup: should be fine for most application and in a small server usage +fpm_usage=low +fpm_footprint=low +### to ajust values, if you have more users like in a NGO or small compagny, see: +### https://github.com/YunoHost/yunohost/blob/dev/helpers/php#L18-L31 +### If the app is more ressources consumming too +ynh_add_fpm_config --usage="$fpm_usage" --footprint="$fpm_footprint" + +#TODO: should this setup should be done directly by the helper? (which default setting then?) +#TODO: or the packager has to decide by its own? (how to decide between 'low' or 'high'?) +#TODO: depending of the app, only the packager can decide the 'default setup' IMO and server admin wil change it if needed. Using 'config panel' I guess? +### alternative setup if you need to use the specific 'conf/php-fpm.conf' file: +### Note that 'conf/extra_php-fpm.conf' will not be used in this scenario! +### ynh_add_fpm_config --use_template #================================================= # NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 1be949b..fb49b29 100755 --- a/scripts/restore +++ b/scripts/restore @@ -36,6 +36,9 @@ db_user=$db_name phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) + #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f38c139..8e49542 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,9 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) + #================================================= # CHECK VERSION #================================================= @@ -101,6 +104,21 @@ if ! ynh_permission_exists --permission="api"; then ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" fi +### Use these functions if the package was released +### without "php fpm footprint" and you are implementing it +### Take values from 'install' script +#If fpm_footprint doesn't exist, create it +if [ -z "$fpm_footprint" ]; then + fpm_footprint=low + ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint +fi + +# If fpm_usage doesn't exist, create it +if [ -z "$fpm_usage" ]; then + fpm_usage=low + ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -144,7 +162,7 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 # Create a dedicated PHP-FPM config -ynh_add_fpm_config +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint #================================================= # NGINX CONFIGURATION