From 0617fcaab782b7d5c6fff6a005561266df56f1b8 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:27:39 +0000 Subject: [PATCH] configpanel update for php --- config_panel.toml | 9 +-- scripts/config | 159 ++++++++++++++++++++-------------------------- 2 files changed, 74 insertions(+), 94 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index b54f7cd..8bd0fc3 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,4 +1,4 @@ -version = "0.1" +version = "1.0" name = "My webapp configuration panel" [main] @@ -21,7 +21,7 @@ name = "My webapp configuration" [main.php_fpm_config] name = "PHP-FPM configuration" - [main.php_fpm_config.footprint] + [main.php_fpm_config.fpm_footprint] ask = "Memory footprint of the service?" choices = ["low", "medium", "high", "specific"] default = "low" @@ -31,10 +31,11 @@ name = "My webapp configuration" ask = "Memory footprint of the service?" type = "number" default = "0" + visible = "match(fpm_footprint, 'specific')" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." - [main.php_fpm_config.usage] + [main.php_fpm_config.fpm_usage] ask = "Expected usage of the service?" choices = ["low", "medium", "high"] default = "low" - help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." + help = "low: Personal usage, behind the SSO. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." diff --git a/scripts/config b/scripts/config index e30a1c3..5ccd0d7 100644 --- a/scripts/config +++ b/scripts/config @@ -9,115 +9,94 @@ source _common.sh source /usr/share/yunohost/helpers +ynh_abort_if_errors + #================================================= # RETRIEVE ARGUMENTS #================================================= -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} +final_path=$(ynh_app_setting_get $app final_path) + +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) #================================================= -# SPECIFIC CODE -#================================================= -# LOAD VALUES +# SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= -# Load the real value from the app config or elsewhere. -# Then get the value from the form. -# If the form has a value for a variable, take the value from the form, -# Otherwise, keep the value from the app config. - -# with_sftp -old_with_sftp="$(ynh_app_setting_get --app=$app --key=with_sftp)" -with_sftp="${YNH_CONFIG_MAIN_SFTP_SFTP:-$old_with_sftp}" - -# sftp password -is_password_exist=0 -password=$(ynh_app_setting_get --app=$app --key=password) -if [ -n "$password" ] -then - ynh_print_warn --message="A password already exist, it will not be replaced." - # If a password already exist, unset the variable password and to not change it. - unset password - is_password_exist=1 -else - # Otherwise, get the new password - password="$YNH_CONFIG_MAIN_SFTP_PASSWORD" -fi - - -# Footprint for PHP-FPM -old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)" -fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}" - -# Free footprint value for PHP-FPM -# Check if fpm_footprint is an integer -if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null -then - # If fpm_footprint is an integer, that's a numeric value for the footprint - old_free_footprint=$fpm_footprint -else - old_free_footprint=0 -fi -free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}" - -# Usage for PHP-FPM -old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)" -fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}" - -#================================================= -# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND -#================================================= - -show_config() { - # here you are supposed to read some config file/database/other then print the values - # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" - ynh_return "YNH_CONFIG_MAIN_SFTP_SFTP=$with_sftp" -# ynh_return "YNH_CONFIG_MAIN_SFTP_PASSWORD=$password" - - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint" - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint" - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage" +get__fpm_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + echo "specific" + else + echo "$current_fpm_footprint" + fi } -#================================================= -# MODIFY THE CONFIGURATION -#================================================= - -apply_config() { - #================================================= - # REMOVE OR ADD SFTP ACCESS - #================================================= - - if [ "$with_sftp" != "$old_with_sftp" ] +get__free_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null then - yunohost app action run $app sftp --args with_sftp=$with_sftp - - # Change the password only if none was already set for the user - if [ $is_password_exist -eq 0 ] && [ $with_sftp -eq 1 ] - then - # Add the password to the user - chpasswd <<< "${app}:${password}" - ynh_app_setting_set --app=$app --key=password --value="$password" - fi + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" fi +} - #================================================= - # RECONFIGURE PHP-FPM - #================================================= - if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= + +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] then - ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} + +set__free_footprint() { + if [ "$fpm_footprint" == "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint" fi } #================================================= # GENERIC FINALIZATION #================================================= -# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT -#================================================= -case $1 in - show) show_config;; - apply) apply_config;; -esac +ynh_app_config_validate() { + _ynh_app_config_validate + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$free_footprint + fi + + if [ "$fpm_footprint" == "0" ] + then + ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + + exit 0 + fi + fi +} + +ynh_app_config_apply() { + _ynh_app_config_apply + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +} + +ynh_app_config_run $1