diff --git a/config_panel.json b/config_panel.json index b4454ae..e605e61 100644 --- a/config_panel.json +++ b/config_panel.json @@ -42,6 +42,33 @@ "type": "bool", "default": true }] + }, + { + "name": "PHP-FPM configuration", + "id": "php_fpm_config", + "options": [{ + "name": "Memory footprint of the service ?", + "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.\n
We can't use a choices field for now. In the meantime please choose between one of this values:\n
low, medium, high, specific.", + "id": "footprint", + "type": "text", + "//": "\"choices\" : [\"low\", \"medium\", \"high\", \"specific\"]", + "default" : "low" + }, + { + "name": "Memory footprint of the service ?", + "help": "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values.", + "id": "free_footprint", + "type": "number", + "default": 0 + }, + { + "name": "Expected usage of the service ?", + "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.\n
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.\n
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding.\n
We can't use a choices field for now. In the meantime please choose between one of this values:\n
low, medium, high.", + "id": "usage", + "type": "text", + "//": "\"choices\" : [\"low\", \"medium\", \"high\"]", + "default" : "low" + }] }] } ] diff --git a/scripts/_ynh_add_fpm_config b/scripts/_ynh_add_fpm_config index 9d4dacf..8d36834 100644 --- a/scripts/_ynh_add_fpm_config +++ b/scripts/_ynh_add_fpm_config @@ -67,6 +67,10 @@ ynh_add_fpm_config () { ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="$finalphpconf" else + # Store settings + ynh_app_setting_set --app=$app --key=fpm_footprint --value=$footprint + ynh_app_setting_set --app=$app --key=fpm_usage --value=$usage + # Usage 2, generate a php-fpm config file with ynh_get_scalable_phpfpm ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint diff --git a/scripts/actions/public_private b/scripts/actions/public_private index 5fb5c62..ebe0cc8 100755 --- a/scripts/actions/public_private +++ b/scripts/actions/public_private @@ -30,7 +30,7 @@ is_public_old=$(ynh_app_setting_get --app=$app --key=is_public) if [ $is_public -eq $is_public_old ] then - ynh_die --message="is_public is already set as $is_public." 0 + ynh_die --message="is_public is already set as $is_public." --ret_code=0 fi #================================================= diff --git a/scripts/config b/scripts/config index 66aea11..6615e6b 100644 --- a/scripts/config +++ b/scripts/config @@ -31,6 +31,7 @@ old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)" old_is_public=$(bool_to_true_false $old_is_public) is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" + # Overwrite nginx configuration old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)" old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx) @@ -41,11 +42,32 @@ old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)" old_overwrite_phpfpm=$(bool_to_true_false $old_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=$app --key=admin_mail_html)" old_admin_mail_html=$(bool_to_true_false $old_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 +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 #================================================= @@ -60,6 +82,10 @@ show_config() { echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm" echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" + + echo "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint" + echo "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint" + echo "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage" } #================================================= @@ -85,6 +111,9 @@ apply_config() { # Set admin_mail_html admin_mail_html=$(bool_to_01 $admin_mail_html) ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" + + # Reconfigure php-fpm + config-panel_scripts/configure_php_fpm --fpm_usage=$fpm_usage --fpm_footprint=$fpm_footprint } #================================================= diff --git a/scripts/config-panel_scripts/configure_php_fpm b/scripts/config-panel_scripts/configure_php_fpm new file mode 100755 index 0000000..abaf34e --- /dev/null +++ b/scripts/config-panel_scripts/configure_php_fpm @@ -0,0 +1,57 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers +source _ynh_add_fpm_config + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +fpm_usage="" +fpm_footprint="" +get_arguments () { + # Use ynh_handle_getopts_args into a function to not interfere with $args_array from helpers. + legacy_args=uf + # Declare an array to define the arguments + declare -Ar args_array=( [u]=fpm_usage= [f]=fpm_footprint= ) + # Manage arguments with getopts + ynh_handle_getopts_args "$@" +} +get_arguments "$@" + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +old_fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) +old_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) + +if [ "$fpm_usage" == "$old_fpm_usage" ] && [ "$fpm_footprint" == "$old_fpm_footprint" ] +then + ynh_die --message="Nothing to change in PHP configuration." --ret_code=0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# RECONFIGURE PHP-FPM CONFIGURATION +#================================================= + +ynh_script_progression --message="Reconfiguring PHP-FPM configuration..." --weight=3 + +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last diff --git a/scripts/upgrade b/scripts/upgrade index a10245a..8e6a0e8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,6 +29,9 @@ overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx) overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm) 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_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) + #================================================= # CHECK VERSION #================================================= @@ -161,7 +164,7 @@ if [ $overwrite_phpfpm -eq 1 ] then ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2 # Create a dedicated php-fpm config - ynh_add_fpm_config --usage=low --footprint=low + ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint fi #=================================================