helpers2.1: autorename phpversion to php_version for consistency with nodejs_version, ruby_version, ...

This commit is contained in:
Alexandre Aubin 2024-06-12 15:53:44 +02:00
parent 66f667e48a
commit d501131b34
3 changed files with 32 additions and 22 deletions

View file

@ -173,11 +173,11 @@ ynh_spawn_app_shell() {
# Force `php` to its intended version # Force `php` to its intended version
# We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export`
local phpversion=$(ynh_app_setting_get --key=phpversion) local php_version=$(ynh_app_setting_get --key=php_version)
local phpflags=$(ynh_app_setting_get --key=phpflags) local phpflags=$(ynh_app_setting_get --key=phpflags)
if [ -n "$phpversion" ] if [ -n "$php_version" ]
then then
eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" eval "php() { php${php_version} ${phpflags} \"\$@\"; }"
export -f php export -f php
fi fi

View file

@ -266,10 +266,10 @@ ynh_install_app_dependencies() {
dependencies+=", php${specific_php_version}, php${specific_php_version}-fpm, php${specific_php_version}-common" dependencies+=", php${specific_php_version}, php${specific_php_version}-fpm, php${specific_php_version}-common"
local old_phpversion=$(ynh_app_setting_get --key=phpversion) local old_php_version=$(ynh_app_setting_get --key=php_version)
# If the PHP version changed, remove the old fpm conf # If the PHP version changed, remove the old fpm conf
if [ -n "$old_phpversion" ] && [ "$old_phpversion" != "$specific_php_version" ]; then if [ -n "$old_php_version" ] && [ "$old_php_version" != "$specific_php_version" ]; then
local old_php_fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir) local old_php_fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir)
local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf" local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf"
@ -279,8 +279,8 @@ ynh_install_app_dependencies() {
ynh_remove_fpm_config ynh_remove_fpm_config
fi fi
fi fi
# Store phpversion into the config of this app # Store php_version into the config of this app
ynh_app_setting_set --key=phpversion --value=$specific_php_version ynh_app_setting_set --key=php_version --value=$specific_php_version
# Set the default php version back as the default version for php-cli. # Set the default php version back as the default version for php-cli.
if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION
@ -288,7 +288,7 @@ ynh_install_app_dependencies() {
update-alternatives --set php /usr/bin/php$YNH_DEFAULT_PHP_VERSION update-alternatives --set php /usr/bin/php$YNH_DEFAULT_PHP_VERSION
fi fi
elif grep --quiet 'php' <<< "$dependencies"; then elif grep --quiet 'php' <<< "$dependencies"; then
ynh_app_setting_set --key=phpversion --value=$YNH_DEFAULT_PHP_VERSION ynh_app_setting_set --key=php_version --value=$YNH_DEFAULT_PHP_VERSION
fi fi
local psql_installed="$(ynh_package_is_installed "postgresql-$PSQL_VERSION" && echo yes || echo no)" local psql_installed="$(ynh_package_is_installed "postgresql-$PSQL_VERSION" && echo yes || echo no)"
@ -339,7 +339,7 @@ EOF
# #
# [packagingv1] # [packagingv1]
# #
# usage: ynh_add_app_dependencies --package=phpversion # usage: ynh_add_app_dependencies --package=packagename
# | arg: -p, --package= - Packages to add as dependencies for the app. # | arg: -p, --package= - Packages to add as dependencies for the app.
# #
# Requires YunoHost version 3.8.1 or higher. # Requires YunoHost version 3.8.1 or higher.

View file

@ -1,9 +1,19 @@
#!/bin/bash #!/bin/bash
# (this is used in the apt helpers, big meh ...)
readonly YNH_DEFAULT_PHP_VERSION=7.4 readonly YNH_DEFAULT_PHP_VERSION=7.4
# Declare the actual PHP version to use.
# A packager willing to use another version of PHP can override the variable into its _common.sh. # Legacy: auto-convert phpversion to php_version (for consistency with nodejs_version, ruby_version, ...)
YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION} if [[ -n "${app:-}" ]] && [[ -n "${phpversion:-}" ]]
then
if [[ -z "${php_version:-}" ]]
then
php_version=$phpversion
ynh_app_setting_set --key=php_version --value=$php_version
fi
ynh_app_setting_delete --key=phpversion
unset phpversion
fi
# Create a dedicated PHP-FPM config # Create a dedicated PHP-FPM config
# #
@ -14,7 +24,7 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION}
# The actual PHP configuration will be automatically generated, # The actual PHP configuration will be automatically generated,
# and your extra_php-fpm.conf will be appended (typically contains PHP upload limits) # and your extra_php-fpm.conf will be appended (typically contains PHP upload limits)
# #
# The resulting configuration will be deployed to the appropriate place, /etc/php/$phpversion/fpm/pool.d/$app.conf # The resulting configuration will be deployed to the appropriate place, /etc/php/$php_version/fpm/pool.d/$app.conf
# #
# Performance-related options in the PHP conf, such as : # Performance-related options in the PHP conf, such as :
# pm.max_children, pm.start_servers, pm.min_spare_servers pm.max_spare_servers # pm.max_children, pm.start_servers, pm.min_spare_servers pm.max_spare_servers
@ -58,8 +68,8 @@ ynh_add_fpm_config() {
# If the PHP version changed, remove the old fpm conf # If the PHP version changed, remove the old fpm conf
# (NB: This stuff is also handled by the apt helper, which is usually triggered before this helper) # (NB: This stuff is also handled by the apt helper, which is usually triggered before this helper)
local old_phpversion=$(ynh_app_setting_get --key=phpversion) local old_php_version=$(ynh_app_setting_get --key=php_version)
if [ -n "$old_phpversion" ] && [ "$old_phpversion" != "$phpversion" ]; then if [ -n "$old_php_version" ] && [ "$old_php_version" != "$php_version" ]; then
local old_php_fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir) local old_php_fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir)
local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf" local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf"
@ -70,15 +80,15 @@ ynh_add_fpm_config() {
fi fi
fi fi
local fpm_service="php${phpversion}-fpm" local fpm_service="php${php_version}-fpm"
local fpm_config_dir="/etc/php/$phpversion/fpm" local fpm_config_dir="/etc/php/$php_version/fpm"
# Create the directory for FPM pools # Create the directory for FPM pools
mkdir --parents "$fpm_config_dir/pool.d" mkdir --parents "$fpm_config_dir/pool.d"
ynh_app_setting_set --key=fpm_config_dir --value="$fpm_config_dir" ynh_app_setting_set --key=fpm_config_dir --value="$fpm_config_dir"
ynh_app_setting_set --key=fpm_service --value="$fpm_service" ynh_app_setting_set --key=fpm_service --value="$fpm_service"
ynh_app_setting_set --key=phpversion --value=$phpversion ynh_app_setting_set --key=php_version --value=$php_version
# Define the values to use for the configuration of PHP. # Define the values to use for the configuration of PHP.
ynh_get_scalable_phpfpm ynh_get_scalable_phpfpm
@ -93,7 +103,7 @@ group = __PHPFPM_GROUP__
chdir = __INSTALL_DIR__ chdir = __INSTALL_DIR__
listen = /var/run/php/php__PHPVERSION__-fpm-__APP__.sock listen = /var/run/php/php__PHP_VERSION__-fpm-__APP__.sock
listen.owner = www-data listen.owner = www-data
listen.group = www-data listen.group = www-data
@ -125,8 +135,8 @@ pm.process_idle_timeout = 10s
ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf" ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf"
# Validate that the new php conf doesn't break php-fpm entirely # Validate that the new php conf doesn't break php-fpm entirely
if ! php-fpm${phpversion} --test 2>/dev/null; then if ! php-fpm${php_version} --test 2>/dev/null; then
php-fpm${phpversion} --test || true php-fpm${php_version} --test || true
ynh_safe_rm "$finalphpconf" ynh_safe_rm "$finalphpconf"
ynh_die --message="The new configuration broke php-fpm?" ynh_die --message="The new configuration broke php-fpm?"
fi fi
@ -298,7 +308,7 @@ ynh_composer_exec() {
# =========================================== # ===========================================
COMPOSER_HOME="$workdir/.composer" COMPOSER_MEMORY_LIMIT=-1 \ COMPOSER_HOME="$workdir/.composer" COMPOSER_MEMORY_LIMIT=-1 \
php${phpversion} "$workdir/composer.phar" $commands \ php${php_version} "$workdir/composer.phar" $commands \
-d "$workdir" --no-interaction --no-ansi 2>&1 -d "$workdir" --no-interaction --no-ansi 2>&1
} }