From 38e6e12553e16488e0f5148ef50f9b913c8836af Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 7 Aug 2022 17:34:22 +0200 Subject: [PATCH] Implement FPM usage and footprint in config panel --- config_panel.toml | 25 ++++++++++++++++++++- scripts/config | 55 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 7 ++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index e05e66c..d2ba140 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -27,10 +27,33 @@ name = "My Webapp configuration" choices = ["none", "7.3", "7.4", "8.0"] default = "none" + [main.php_fpm_config.fpm_footprint] + ask = "Memory footprint of the service?" + type = "select" + choices.low = "Low, <= 20Mb per pool" + choices.medium = "Medium, between 20Mb and 40Mb per pool" + choices.high = "High, > 40Mb per pool" + choices.specific = "Use specific value" + default = "low" + + [main.php_fpm_config.fpm_free_footprint] + visible = "fpm_footprint == 'specific'" + ask = "Memory footprint of the service?" + type = "number" + default = "0" + 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.fpm_usage] + ask = "Expected usage of the service?" + type = "select" + 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." + # TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path # [main.permissions] # [main.permissions.proteced_path] # ask = "Protected path" # help = "A permission will be created so you can restrict the access to a subpath of the web app." # type = "tags" - \ No newline at end of file + diff --git a/scripts/config b/scripts/config index b853d6b..188b1b6 100644 --- a/scripts/config +++ b/scripts/config @@ -19,6 +19,7 @@ final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) @@ -26,6 +27,29 @@ fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= +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 +} + +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 + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" + fi +} + #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -41,6 +65,20 @@ set__password() { fi } +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} + +set__fpm_free_footprint() { + if [ "$fpm_footprint" = "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint" + fi +} + #================================================= # GENERIC FINALIZATION #================================================= @@ -52,6 +90,21 @@ ynh_app_config_validate() { then ynh_die --message="You need to set a password to enable SFTP" fi + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $fpm_free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$fpm_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() { @@ -91,6 +144,8 @@ ynh_app_config_apply() { then ynh_system_user_del_group --username=$app --groups="sftp.app" fi + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint } ynh_app_config_run $1 diff --git a/scripts/upgrade b/scripts/upgrade index 9a38aa2..71dd841 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,6 +28,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html) fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +fpm_free_footprint=$(ynh_app_setting_get --app=$app --key=fpm_free_footprint) fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= @@ -79,6 +80,12 @@ if [ -z "$fpm_footprint" ]; then ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint fi +# If fpm_free_footprint doesn't exist, create it +if [ -z "$fpm_free_footprint" ]; then + fpm_free_footprint=0 + ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint +fi + # If fpm_usage doesn't exist, create it if [ -z "$fpm_usage" ]; then fpm_usage=low