mirror of
https://github.com/YunoHost-Apps/wordpress_ynh.git
synced 2024-09-03 20:36:10 +02:00
Config Panel v1
This commit is contained in:
parent
046f45527b
commit
acae00b583
3 changed files with 104 additions and 139 deletions
|
@ -1,9 +1,15 @@
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
name = "Wordpress configuration panel"
|
|
||||||
|
|
||||||
[main]
|
[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]
|
[main.overwrite_files]
|
||||||
name = "Overwriting config files"
|
name = "Overwriting config files"
|
||||||
|
@ -20,40 +26,37 @@ name = "Wordpress configuration"
|
||||||
default = true
|
default = true
|
||||||
help = "If the file is overwritten, a backup will be created."
|
help = "If the file is overwritten, a backup will be created."
|
||||||
|
|
||||||
|
|
||||||
[main.global_config]
|
[main.global_config]
|
||||||
name = "Global configuration"
|
name = "Global configuration"
|
||||||
|
|
||||||
[main.global_config.email_type]
|
[main.global_config.admin_mail_html]
|
||||||
ask = "Send HTML email to admin?"
|
ask = "Send HTML email to admin?"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
default = true
|
default = true
|
||||||
help = "Allow app scripts to send HTML mails instead of plain text."
|
help = "Allow app scripts to send HTML mails instead of plain text."
|
||||||
|
|
||||||
|
|
||||||
[main.php_fpm_config]
|
[main.php_fpm_config]
|
||||||
name = "PHP-FPM configuration"
|
name = "PHP-FPM configuration"
|
||||||
|
|
||||||
[main.php_fpm_config.footprint]
|
[main.php_fpm_config.fpm_footprint]
|
||||||
ask = "Memory footprint of the service?"
|
ask = "Memory footprint"
|
||||||
choices = ["low", "medium", "high", "specific"]
|
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"
|
default = "low"
|
||||||
help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.<br>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?"
|
ask = "Memory footprint of the service?"
|
||||||
type = "number"
|
type = "number"
|
||||||
default = "0"
|
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."
|
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?"
|
ask = "Expected usage"
|
||||||
|
type = "select"
|
||||||
choices = ["low", "medium", "high"]
|
choices = ["low", "medium", "high"]
|
||||||
default = "low"
|
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.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>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.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>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!<br>pm.max_children is automatically defined by this formula: $max_ram / 2 / $footprint<br>You can force that value, and ignore the formula by changing the value here.<br>To reset to the default value, set to 0."
|
|
204
scripts/config
204
scripts/config
|
@ -9,149 +9,111 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RETRIEVE ARGUMENTS
|
# RETRIEVE ARGUMENTS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||||
|
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
||||||
fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
|
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD VALUES
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Load the real value from the app config or elsewhere.
|
get__maintenance_mode() {
|
||||||
# Then get the value from the form.
|
# Maintenance mode status
|
||||||
# If the form has a value for a variable, take the value from the form,
|
if [ -f $final_path/.maintenance ]
|
||||||
# Otherwise, keep the value from the app config.
|
then
|
||||||
|
echo "1"
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Overwrite nginx configuration
|
get__fpm_footprint() {
|
||||||
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
|
# Free footprint value for php-fpm
|
||||||
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
|
# 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
|
get__free_footprint() {
|
||||||
old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)"
|
# Free footprint value for php-fpm
|
||||||
overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
|
# Check if current_fpm_footprint is an integer
|
||||||
|
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
|
||||||
# Type of admin mail configuration
|
then
|
||||||
old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)"
|
# If current_fpm_footprint is an integer, that's a numeric value for the footprint
|
||||||
admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
|
echo "$current_fpm_footprint"
|
||||||
|
else
|
||||||
# Footprint for php-fpm
|
echo "0"
|
||||||
old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
|
fi
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# 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"
|
||||||
|
}
|
||||||
|
|
||||||
#=================================================
|
set__fpm_footprint() {
|
||||||
# MODIFY OVERWRITTING SETTINGS
|
if [ "$fpm_footprint" != "specific" ]
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# 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" ]
|
|
||||||
then
|
then
|
||||||
# If fpm_footprint is set to 'specific', use $free_footprint value.
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
|
||||||
if [ "$fpm_footprint" = "specific" ]
|
fi
|
||||||
then
|
}
|
||||||
fpm_footprint=$free_footprint
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
|
set__fpm_free_footprint() {
|
||||||
then
|
if [ "$fpm_footprint" = "specific" ]
|
||||||
# Set php_forced_max_children
|
then
|
||||||
if [ $php_forced_max_children -ne 0 ]
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint"
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
case $1 in
|
ynh_app_config_validate() {
|
||||||
show) show_config;;
|
_ynh_app_config_validate
|
||||||
apply) apply_config;;
|
|
||||||
esac
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue