mirror of
https://github.com/YunoHost-Apps/leed_ynh.git
synced 2024-09-03 19:26:32 +02:00
Add config-panel option for php configuration
This commit is contained in:
parent
a5154178fa
commit
05eaf1b21e
6 changed files with 122 additions and 2 deletions
|
@ -42,6 +42,33 @@
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default": true
|
"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<br>We can't use a choices field for now. In the meantime please choose between one of this values:\n<br>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<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.\n<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding.\n<br>We can't use a choices field for now. In the meantime please choose between one of this values:\n<br>low, medium, high.",
|
||||||
|
"id": "usage",
|
||||||
|
"type": "text",
|
||||||
|
"//": "\"choices\" : [\"low\", \"medium\", \"high\"]",
|
||||||
|
"default" : "low"
|
||||||
|
}]
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -67,6 +67,10 @@ ynh_add_fpm_config () {
|
||||||
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="$finalphpconf"
|
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="$finalphpconf"
|
||||||
|
|
||||||
else
|
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
|
# Usage 2, generate a php-fpm config file with ynh_get_scalable_phpfpm
|
||||||
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ is_public_old=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
|
||||||
if [ $is_public -eq $is_public_old ]
|
if [ $is_public -eq $is_public_old ]
|
||||||
then
|
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
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -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)
|
old_is_public=$(bool_to_true_false $old_is_public)
|
||||||
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
|
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
|
||||||
|
|
||||||
|
|
||||||
# Overwrite nginx configuration
|
# Overwrite nginx configuration
|
||||||
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
|
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
|
||||||
old_overwrite_nginx=$(bool_to_true_false $old_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)
|
old_overwrite_phpfpm=$(bool_to_true_false $old_overwrite_phpfpm)
|
||||||
overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
|
overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
|
||||||
|
|
||||||
|
|
||||||
# Type of admin mail configuration
|
# Type of admin mail configuration
|
||||||
old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
|
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)
|
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}"
|
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
|
# 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_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
|
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
|
# Set admin_mail_html
|
||||||
admin_mail_html=$(bool_to_01 $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"
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
57
scripts/config-panel_scripts/configure_php_fpm
Executable file
57
scripts/config-panel_scripts/configure_php_fpm
Executable file
|
@ -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
|
|
@ -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)
|
overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)
|
||||||
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
|
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
|
# CHECK VERSION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -161,7 +164,7 @@ if [ $overwrite_phpfpm -eq 1 ]
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
|
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
|
||||||
# Create a dedicated php-fpm config
|
# 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
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue