From a2dccc42f6f0ff01f2ca949a0bb67b0ca051b4a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89ric=20Gaspar?=
<46165813+ericgaspar@users.noreply.github.com>
Date: Tue, 27 Dec 2022 15:00:56 +0100
Subject: [PATCH] Fix PHP
---
conf/nginx.conf | 2 +-
config_panel.toml | 30 +++++++++++++++
scripts/config | 95 +++++++++++++++++++++++++++++++++++++++++++++++
scripts/install | 8 +++-
scripts/upgrade | 24 +++++++++++-
5 files changed, 156 insertions(+), 3 deletions(-)
create mode 100644 config_panel.toml
create mode 100644 scripts/config
diff --git a/conf/nginx.conf b/conf/nginx.conf
index f440085a..b17c3540 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -13,7 +13,7 @@ location __PATH__/ {
charset utf-8;
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
- client_max_body_size 50m;
+ client_max_body_size 50M;
client_body_buffer_size 128k;
location ~* \.php$ {
diff --git a/config_panel.toml b/config_panel.toml
new file mode 100644
index 00000000..e23bed17
--- /dev/null
+++ b/config_panel.toml
@@ -0,0 +1,30 @@
+version = "1.0"
+
+[main]
+name = "Hibzilla configuration"
+
+ [main.php_fpm_config]
+ name = "PHP-FPM configuration"
+
+ [main.php_fpm_config.fpm_footprint]
+ ask = "Memory footprint"
+ 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"
+
+ [main.php_fpm_config.fpm_free_footprint]
+ visible = "fpm_footprint == 'specific'"
+ 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.fpm_usage]
+ ask = "Expected usage"
+ 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.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
diff --git a/scripts/config b/scripts/config
new file mode 100644
index 00000000..91c2de75
--- /dev/null
+++ b/scripts/config
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+ynh_abort_if_errors
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
+current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+
+#=================================================
+# SPECIFIC GETTERS FOR TOML SHORT KEY
+#=================================================
+
+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
+}
+
+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
+}
+
+#=================================================
+# SPECIFIC SETTERS FOR TOML SHORT KEYS
+#=================================================
+
+set__fpm_footprint() {
+ if [ "$fpm_footprint" != "specific" ]
+ then
+ ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
+ 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
+#=================================================
+
+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
diff --git a/scripts/install b/scripts/install
index 82d1c4a4..2e60fd96 100755
--- a/scripts/install
+++ b/scripts/install
@@ -33,6 +33,9 @@ app=$YNH_APP_INSTANCE_NAME
email=$(ynh_user_get_info --username=$admin --key=mail)
upload="256M"
random_string="$(ynh_string_random --length=48)"
+fpm_footprint="low"
+fpm_free_footprint=0
+fpm_usage="low"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@@ -57,6 +60,9 @@ ynh_app_setting_set --app=$app --key=database --value=$database
ynh_app_setting_set --app=$app --key=email --value=$email
ynh_app_setting_set --app=$app --key=upload --value=$upload
ynh_app_setting_set --app=$app --key=random_string --value=$random_string
+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
#=================================================
# STANDARD MODIFICATIONS
@@ -121,7 +127,7 @@ chmod -R 775 $final_path/store $final_path/cache
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
# Create a dedicated PHP-FPM config
-ynh_add_fpm_config
+ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
diff --git a/scripts/upgrade b/scripts/upgrade
index 49a41324..596b7566 100755
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -28,6 +28,9 @@ upload=$(ynh_app_setting_get --app=$app --key=upload)
random_string=$(ynh_app_setting_get --app=$app --key=random_string)
email=$(ynh_user_get_info --username=$admin --key=mail)
+fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+fpm_free_footprint=$(ynh_app_setting_get --app=$app --key=fpm_free_footprint)
+fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
#=================================================
# CHECK VERSION
@@ -69,6 +72,24 @@ if [ -z "$db_name" ]; then
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
+# If fpm_footprint doesn't exist, create it
+if [ -z "$fpm_footprint" ]; then
+ fpm_footprint=low
+ 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=low
+ ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
+fi
+
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@@ -129,7 +150,8 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
# Create a dedicated PHP-FPM config
-ynh_add_fpm_config
+ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
+phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# NGINX CONFIGURATION