mirror of
https://github.com/YunoHost-Apps/my_webapp_ynh.git
synced 2024-09-03 19:46:26 +02:00
configpanel update for php
This commit is contained in:
parent
f1fb0c9c08
commit
0617fcaab7
2 changed files with 74 additions and 94 deletions
|
@ -1,4 +1,4 @@
|
||||||
version = "0.1"
|
version = "1.0"
|
||||||
name = "My webapp configuration panel"
|
name = "My webapp configuration panel"
|
||||||
|
|
||||||
[main]
|
[main]
|
||||||
|
@ -21,7 +21,7 @@ name = "My webapp configuration"
|
||||||
[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 of the service?"
|
||||||
choices = ["low", "medium", "high", "specific"]
|
choices = ["low", "medium", "high", "specific"]
|
||||||
default = "low"
|
default = "low"
|
||||||
|
@ -31,10 +31,11 @@ name = "My webapp configuration"
|
||||||
ask = "Memory footprint of the service?"
|
ask = "Memory footprint of the service?"
|
||||||
type = "number"
|
type = "number"
|
||||||
default = "0"
|
default = "0"
|
||||||
|
visible = "match(fpm_footprint, 'specific')"
|
||||||
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 of the service?"
|
||||||
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."
|
||||||
|
|
153
scripts/config
153
scripts/config
|
@ -9,115 +9,94 @@
|
||||||
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:-$YNH_APP_ID}
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||||
|
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC CODE
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
#=================================================
|
|
||||||
# LOAD VALUES
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Load the real value from the app config or elsewhere.
|
get__fpm_footprint() {
|
||||||
# Then get the value from the form.
|
# Free footprint value for php-fpm
|
||||||
# If the form has a value for a variable, take the value from the form,
|
# Check if current_fpm_footprint is an integer
|
||||||
# Otherwise, keep the value from the app config.
|
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
|
||||||
|
then
|
||||||
# with_sftp
|
echo "specific"
|
||||||
old_with_sftp="$(ynh_app_setting_get --app=$app --key=with_sftp)"
|
else
|
||||||
with_sftp="${YNH_CONFIG_MAIN_SFTP_SFTP:-$old_with_sftp}"
|
echo "$current_fpm_footprint"
|
||||||
|
fi
|
||||||
# sftp password
|
|
||||||
is_password_exist=0
|
|
||||||
password=$(ynh_app_setting_get --app=$app --key=password)
|
|
||||||
if [ -n "$password" ]
|
|
||||||
then
|
|
||||||
ynh_print_warn --message="A password already exist, it will not be replaced."
|
|
||||||
# If a password already exist, unset the variable password and to not change it.
|
|
||||||
unset password
|
|
||||||
is_password_exist=1
|
|
||||||
else
|
|
||||||
# Otherwise, get the new password
|
|
||||||
password="$YNH_CONFIG_MAIN_SFTP_PASSWORD"
|
|
||||||
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}"
|
|
||||||
|
|
||||||
# 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() {
|
|
||||||
# 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_SFTP_SFTP=$with_sftp"
|
|
||||||
# ynh_return "YNH_CONFIG_MAIN_SFTP_PASSWORD=$password"
|
|
||||||
|
|
||||||
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 VALIDATORS FOR TOML SHORT KEYS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
apply_config() {
|
#=================================================
|
||||||
#=================================================
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||||
# REMOVE OR ADD SFTP ACCESS
|
#=================================================
|
||||||
#=================================================
|
|
||||||
|
|
||||||
if [ "$with_sftp" != "$old_with_sftp" ]
|
set__fpm_footprint() {
|
||||||
|
if [ "$fpm_footprint" != "specific" ]
|
||||||
then
|
then
|
||||||
yunohost app action run $app sftp --args with_sftp=$with_sftp
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
|
||||||
|
|
||||||
# Change the password only if none was already set for the user
|
|
||||||
if [ $is_password_exist -eq 0 ] && [ $with_sftp -eq 1 ]
|
|
||||||
then
|
|
||||||
# Add the password to the user
|
|
||||||
chpasswd <<< "${app}:${password}"
|
|
||||||
ynh_app_setting_set --app=$app --key=password --value="$password"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#=================================================
|
set__free_footprint() {
|
||||||
# RECONFIGURE PHP-FPM
|
if [ "$fpm_footprint" == "specific" ]
|
||||||
#=================================================
|
|
||||||
|
|
||||||
if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ]
|
|
||||||
then
|
then
|
||||||
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint"
|
||||||
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[free_footprint]}" == "true" ]; then
|
||||||
|
# If fpm_footprint is set to 'specific', use $free_footprint value.
|
||||||
|
if [ "$fpm_footprint" = "specific" ]
|
||||||
|
then
|
||||||
|
fpm_footprint=$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