From acae00b583eb41a1f86a9057923bf52c1cf67d03 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 17 Sep 2022 12:50:04 +0200 Subject: [PATCH] Config Panel v1 --- actions.toml => actions.toml.old | 0 ...ig_panel.toml.example => config_panel.toml | 39 ++-- scripts/config | 204 +++++++----------- 3 files changed, 104 insertions(+), 139 deletions(-) rename actions.toml => actions.toml.old (100%) rename config_panel.toml.example => config_panel.toml (61%) diff --git a/actions.toml b/actions.toml.old similarity index 100% rename from actions.toml rename to actions.toml.old diff --git a/config_panel.toml.example b/config_panel.toml similarity index 61% rename from config_panel.toml.example rename to config_panel.toml index 5104992..87940cc 100644 --- a/config_panel.toml.example +++ b/config_panel.toml @@ -1,9 +1,15 @@ version = "1.0" -name = "Wordpress configuration panel" [main] -name = "Wordpress configuration" +name = "WordPress configuration" + [main.maintenance_mode] + name = "Maintenance mode" + + [main.maintenance_mode.maintenance_mode] + ask = "Enable maintenance mode" + type = "boolean" + default = "0" [main.overwrite_files] name = "Overwriting config files" @@ -20,40 +26,37 @@ name = "Wordpress configuration" default = true help = "If the file is overwritten, a backup will be created." - [main.global_config] name = "Global configuration" - [main.global_config.email_type] + [main.global_config.admin_mail_html] ask = "Send HTML email to admin?" type = "boolean" default = true help = "Allow app scripts to send HTML mails instead of plain text." - [main.php_fpm_config] name = "PHP-FPM configuration" - [main.php_fpm_config.footprint] - ask = "Memory footprint of the service?" - choices = ["low", "medium", "high", "specific"] + [main.php_fpm_config.fpm_footprint] + ask = "Memory footprint" + 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" - help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.
Use specific to set a value with the following option." - [main.php_fpm_config.free_footprint] + [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.usage] - ask = "Expected usage of the service?" + [main.php_fpm_config.fpm_usage] + ask = "Expected usage" + 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." - - [main.php_fpm_config.force_max_children] - ask = "Force the value of pm.max_children?" - type = "number" - default = "0" - help = "Do not change this value unless you are sure about what you are doing!
pm.max_children is automatically defined by this formula: $max_ram / 2 / $footprint
You can force that value, and ignore the formula by changing the value here.
To reset to the default value, set to 0." diff --git a/scripts/config b/scripts/config index 1b77851..0a9e083 100644 --- a/scripts/config +++ b/scripts/config @@ -9,149 +9,111 @@ source _common.sh source /usr/share/yunohost/helpers +ynh_abort_if_errors + #================================================= # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME - -fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) #================================================= -# 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. +get__maintenance_mode() { + # Maintenance mode status + if [ -f $final_path/.maintenance ] + then + echo "1" + else + echo "0" + fi +} -# Overwrite nginx configuration -old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)" -overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}" +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 +} -# Overwrite php-fpm configuration -old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)" -overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}" - -# Type of admin mail configuration -old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)" -admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" - -# 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 - fpm_footprint=specific -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}" - -# php_forced_max_children for php-fpm -old_php_forced_max_children="$(ynh_app_setting_get --app=$app --key=php_forced_max_children)" -# If php_forced_max_children isn't into settings.yml, get the current value from the fpm config -if [ -z "$old_php_forced_max_children" ]; then - old_php_forced_max_children="$(grep "^pm.max_children" "$fpm_config_dir/pool.d/$app.conf" | awk '{print $3}')" -fi -php_forced_max_children="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN:-$old_php_forced_max_children}" - -#================================================= -# 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_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" - ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm" - - ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" - - 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" - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN=$php_forced_max_children" +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 } #================================================= -# MODIFY THE CONFIGURATION +# SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= -apply_config() { +set__maintenance_mode() { + if [ "$maintenance_mode" -eq "1" ]; then + # If maintenance_mode was set to 1, enable maintenance mode + (cd "$final_path" && ynh_exec_as "$app" \ + echo "Site under maintenance." > .maintenance) + ynh_print_info "Maintenance mode disabled" + elif [ "$maintenance_mode" -eq "0" ]; then + # If maintenance_mode was set to 0, disable maintenance mode + ynh_secure_remove --file=$final_path/.maintenance + ynh_print_info "Maintenance mode enabled" + fi + ynh_app_setting_set --app=$app --key=maintenance_mode --value="$maintenance_mode" +} - #================================================= - # MODIFY OVERWRITTING SETTINGS - #================================================= - - # Set overwrite_nginx - ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx" - - # Set overwrite_phpfpm - ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm" - - #================================================= - # MODIFY EMAIL SETTING - #================================================= - - # Set admin_mail_html - ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" - - #================================================= - # RECONFIGURE PHP-FPM - #================================================= - - if [ "$fpm_usage" != "$old_fpm_usage" ] || \ - [ "$fpm_footprint" != "$old_fpm_footprint" ] || \ - [ "$free_footprint" != "$old_free_footprint" ] || \ - [ "$php_forced_max_children" != "$old_php_forced_max_children" ] +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] then - # If fpm_footprint is set to 'specific', use $free_footprint value. - if [ "$fpm_footprint" = "specific" ] - then - fpm_footprint=$free_footprint - fi + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} - if [ "$php_forced_max_children" != "$old_php_forced_max_children" ] - then - # Set php_forced_max_children - if [ $php_forced_max_children -ne 0 ] - then - ynh_app_setting_set --app=$app --key=php_forced_max_children --value="$php_forced_max_children" - else - # If the value is set to 0, remove the setting - ynh_app_setting_delete --app=$app --key=php_forced_max_children - fi - fi - - if [ "$fpm_footprint" != "0" ] - then - ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint - else - ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." - 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 #================================================= -# 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[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() { + _ynh_app_config_apply + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +} + +ynh_app_config_run $1