mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
Implement Config Panels v1.0 (PHP and maintenance mode)
This commit is contained in:
parent
41f5f902e7
commit
890941eaa9
4 changed files with 132 additions and 69 deletions
|
@ -1,26 +1,37 @@
|
|||
version = "0.1"
|
||||
name = "Nextcloud configuration panel"
|
||||
version = "1.0"
|
||||
|
||||
[main]
|
||||
name = "Nextcloud configuration"
|
||||
|
||||
[main.maintenance_mode]
|
||||
name = "Maintenance mode"
|
||||
|
||||
[main.maintenance_mode.maintenance_mode]
|
||||
ask = "Enable Nextcloud's maintenance mode?"
|
||||
type = "boolean"
|
||||
default = "0"
|
||||
|
||||
[main.php_fpm_config]
|
||||
name = "PHP-FPM configuration"
|
||||
|
||||
[main.php_fpm_config.footprint]
|
||||
[main.php_fpm_config.fpm_footprint]
|
||||
ask = "Memory footprint of the service?"
|
||||
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 from the next option"
|
||||
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]
|
||||
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]
|
||||
[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.<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."
|
||||
|
|
150
scripts/config
150
scripts/config
|
@ -9,90 +9,118 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# 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)
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
maintenance_mode_status="$(cd "$final_path" && ynh_exec_as "$app" \
|
||||
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode)" 2> /dev/null
|
||||
if echo $maintenance_mode_status | grep -q "disabled"
|
||||
then
|
||||
echo "0"
|
||||
elif echo $maintenance_mode_status | grep -q "enabled"
|
||||
then
|
||||
echo "1"
|
||||
else
|
||||
ynh_print_err --message="Unexpected output from maintenance status check command."
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# 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}"
|
||||
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
|
||||
}
|
||||
|
||||
# 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}"
|
||||
|
||||
#=================================================
|
||||
# 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_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"
|
||||
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 "0" ]; then
|
||||
# If maintenance_mode was set to 0, disable maintenance mode
|
||||
(cd "$final_path" && ynh_exec_as "$app" \
|
||||
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --off)
|
||||
ynh_print_info "Maintenance mode disabled"
|
||||
elif [ "$maintenance_mode" -eq "1" ]; then
|
||||
# If maintenance_mode was set to 1, enable maintenance mode
|
||||
(cd "$final_path" && ynh_exec_as "$app" \
|
||||
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --on)
|
||||
ynh_print_info "Maintenance mode enabled"
|
||||
fi
|
||||
ynh_app_setting_set --app=$app --key=maintenance_mode --value="$maintenance_mode"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# RECONFIGURE PHP-FPM
|
||||
#=================================================
|
||||
|
||||
if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] || [ "$free_footprint" != "$old_free_footprint" ]
|
||||
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 [ "$fpm_footprint" != "0" ]
|
||||
then
|
||||
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint --package="$extra_php_dependencies"
|
||||
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
|
||||
|
|
|
@ -49,6 +49,9 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||
ynh_app_setting_set --app=$app --key=user_home --value=$user_home
|
||||
|
||||
maintenance_mode=0
|
||||
ynh_app_setting_set --app=$app --key=maintenance_mode --value=$maintenance_mode
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
|
@ -103,8 +106,16 @@ ynh_system_user_create --username=$app
|
|||
#=================================================
|
||||
ynh_script_progression --message="Configuring PHP-FPM..." --weight=50
|
||||
|
||||
fpm_footprint="high"
|
||||
fpm_free_footprint=0
|
||||
fpm_usage="medium"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
|
||||
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
|
||||
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config --usage=medium --footprint=high --phpversion=$YNH_PHP_VERSION
|
||||
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$YNH_PHP_VERSION
|
||||
# Used by ynh_add_nginx_config
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|||
user_home=$(ynh_app_setting_get --app=$app --key=user_home)
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
maintenance_mode=$(ynh_app_setting_get --app=$app --key=maintenance_mode)
|
||||
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
||||
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
||||
|
||||
|
@ -59,12 +60,24 @@ fi
|
|||
# Remove the option backup_core_only if it's in the settings.yml file
|
||||
ynh_app_setting_delete --app=$app --key=backup_core_only
|
||||
|
||||
# If maintenance_mode doesn't exist, create it
|
||||
if [ -z "$maintenance_mode" ]; then
|
||||
maintenance_mode=0
|
||||
ynh_app_setting_set --app=$app --key=maintenance_mode --value=$maintenance_mode
|
||||
fi
|
||||
|
||||
# If fpm_footprint doesn't exist, create it
|
||||
if [ -z "$fpm_footprint" ]; then
|
||||
fpm_footprint=high
|
||||
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=medium
|
||||
|
|
Loading…
Add table
Reference in a new issue