mirror of
https://github.com/YunoHost-Apps/phpinfo_ynh.git
synced 2024-09-03 19:56:23 +02:00
Update ynh_install_php
This commit is contained in:
parent
cdcef290ad
commit
d7af0cdff9
1 changed files with 280 additions and 280 deletions
|
@ -17,240 +17,70 @@ export PHPENV_ROOT="$phpenv_install_dir"
|
|||
# Required dependencies
|
||||
phpenv_dependencies="autoconf2.13 autoconf2.64 autoconf bash bison build-essential ca-certificates curl findutils git libbz2-dev libcurl4-gnutls-dev libicu-dev libjpeg-dev libmcrypt-dev libonig-dev libpng-dev libreadline-dev libsqlite3-dev libssl-dev libtidy-dev libxml2-dev libxslt1-dev libzip-dev pkg-config re2c zlib1g-dev"
|
||||
|
||||
# Create a dedicated PHP-FPM config
|
||||
# Load the version of PHP for an app, and set variables.
|
||||
#
|
||||
# usage 1: ynh_add_fpm_config [--phpversion=7.X] [--use_template] [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion= - Version of PHP to use.
|
||||
# | arg: -t, --use_template - Use this helper in template mode.
|
||||
# | arg: -p, --package= - Additionnal PHP packages to install
|
||||
# | arg: -d, --dedicated_service - Use a dedicated PHP-FPM service instead of the common one.
|
||||
# ynh_use_php has to be used in any app scripts before using PHP for the first time.
|
||||
# This helper will provide alias and variables to use in your scripts.
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
# To use gem or PHP, use the alias `ynh_gem` and `ynh_php`
|
||||
# Those alias will use the correct version installed for the app
|
||||
# For example: use `ynh_gem install` instead of `gem install`
|
||||
#
|
||||
# usage 2: ynh_add_fpm_config [--phpversion=7.X] --usage=usage --footprint=footprint [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion= - Version of PHP to use.
|
||||
# | arg: -f, --footprint= - Memory footprint of the service (low/medium/high).
|
||||
# low - Less than 20 MB of RAM by pool.
|
||||
# medium - Between 20 MB and 40 MB of RAM by pool.
|
||||
# high - More than 40 MB of RAM by pool.
|
||||
# Or specify exactly the footprint, the load of the service as MB by pool instead of having a standard value.
|
||||
# To have this value, use the following command and stress the service.
|
||||
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
|
||||
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_php`
|
||||
# And propagate $PATH to sudo with $ynh_php_load_path
|
||||
# Exemple: `ynh_exec_as $app $ynh_php_load_path $ynh_gem install`
|
||||
#
|
||||
# | arg: -u, --usage= - Expected usage of the service (low/medium/high).
|
||||
# low - Personal usage, behind the SSO.
|
||||
# medium - Low usage, few people or/and publicly accessible.
|
||||
# high - High usage, frequently visited website.
|
||||
#
|
||||
# | arg: -p, --package= - Additionnal PHP packages to install for a specific version of PHP
|
||||
# | arg: -d, --dedicated_service - Use a dedicated PHP-FPM service instead of the common one.
|
||||
# $PATH contains the path of the requested version of PHP.
|
||||
# However, $PATH is duplicated into $php_path to outlast any manipulation of $PATH
|
||||
# You can use the variable `$ynh_php_load_path` to quickly load your PHP version
|
||||
# in $PATH for an usage into a separate script.
|
||||
# Exemple: $ynh_php_load_path $final_path/script_that_use_gem.sh`
|
||||
#
|
||||
#
|
||||
ynh_add_fpm_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vtufpd
|
||||
local -A args_array=( [v]=phpversion= [t]=use_template [u]=usage= [f]=footprint= [p]=package= [d]=dedicated_service )
|
||||
local phpversion
|
||||
local use_template
|
||||
local usage
|
||||
local footprint
|
||||
local package
|
||||
local dedicated_service
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
package=${package:-}
|
||||
# Finally, to start a PHP service with the correct version, 2 solutions
|
||||
# Either the app is dependent of PHP or gem, but does not called it directly.
|
||||
# In such situation, you need to load PATH
|
||||
# `Environment="__YNH_PHP_LOAD_ENV_PATH__"`
|
||||
# `ExecStart=__FINALPATH__/my_app`
|
||||
# You will replace __YNH_PHP_LOAD_ENV_PATH__ with $ynh_php_load_path
|
||||
#
|
||||
# Or PHP start the app directly, then you don't need to load the PATH variable
|
||||
# `ExecStart=__YNH_PHP__ my_app run`
|
||||
# You will replace __YNH_PHP__ with $ynh_php
|
||||
#
|
||||
#
|
||||
# one other variable is also available
|
||||
# - $php_path: The absolute path to PHP binaries for the chosen version.
|
||||
#
|
||||
# usage: ynh_use_php
|
||||
#
|
||||
# Requires YunoHost version 2.7.12 or higher.
|
||||
ynh_use_php () {
|
||||
php_version=$(ynh_app_setting_get --app=$app --key=php_version)
|
||||
|
||||
# The default behaviour is to use the template.
|
||||
use_template="${use_template:-1}"
|
||||
usage="${usage:-}"
|
||||
footprint="${footprint:-}"
|
||||
if [ -n "$usage" ] || [ -n "$footprint" ]; then
|
||||
use_template=0
|
||||
# Get the absolute path of this version of PHP
|
||||
php_path="$php_version_path/$php_version/bin"
|
||||
|
||||
# Allow alias to be used into bash script
|
||||
shopt -s expand_aliases
|
||||
|
||||
# Create an alias for the specific version of PHP and a variable as fallback
|
||||
ynh_php="$php_path/php"
|
||||
alias ynh_php="$ynh_php"
|
||||
|
||||
ynh_fpm_conf="$php_version_path/$php_version/etc/php-fpm.d/$YNH_APP_INSTANCE_NAME.conf"
|
||||
|
||||
# Load the path of this version of PHP in $PATH
|
||||
if [[ :$PATH: != *":$php_path"* ]]; then
|
||||
PATH="$php_path:$PATH"
|
||||
fi
|
||||
# Do not use a dedicated service by default
|
||||
dedicated_service=${dedicated_service:-0}
|
||||
# Create an alias to easily load the PATH
|
||||
ynh_php_load_path="PATH=$PATH"
|
||||
|
||||
phpversion=""
|
||||
local php_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=php_version)
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
local fpm_service="${app}-phpfpm"
|
||||
local fpm_config_dir="$php_version_path/$php_version/etc/dedicated-fpm"
|
||||
else
|
||||
local fpm_service="php${php_version}-fpm"
|
||||
local fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
fi
|
||||
|
||||
# Create the directory for FPM pools
|
||||
mkdir --parents "$fpm_config_dir"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=fpm_config_dir --value="$fpm_config_dir"
|
||||
ynh_app_setting_set --app=$app --key=fpm_service --value="$fpm_service"
|
||||
ynh_app_setting_set --app=$app --key=fpm_dedicated_service --value="$dedicated_service"
|
||||
|
||||
# Migrate from mutual PHP service to dedicated one.
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
local old_fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
# If a config file exist in the common pool, move it.
|
||||
if [ -e "$old_fpm_config_dir/$app.conf" ]
|
||||
then
|
||||
ynh_print_info --message="Migrate to a dedicated php-fpm service for $app."
|
||||
# Create a backup of the old file before migration
|
||||
ynh_backup_if_checksum_is_different --file="$old_fpm_config_dir/$app.conf"
|
||||
# Remove the old PHP config file
|
||||
ynh_secure_remove --file="$old_fpm_config_dir/$app.conf"
|
||||
# Reload PHP to release the socket and allow the dedicated service to use it
|
||||
ynh_systemd_action --service_name=php${php_version}-fpm --action=reload
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $use_template -eq 1 ]
|
||||
then
|
||||
# Usage 1, use the template in conf/php-fpm.conf
|
||||
local phpfpm_path="../conf/php-fpm.conf"
|
||||
# Make sure now that the template indeed exists
|
||||
[ -e "$phpfpm_path" ] || ynh_die --message="Unable to find template to configure PHP-FPM."
|
||||
else
|
||||
# Usage 2, generate a PHP-FPM config file with ynh_get_scalable_phpfpm
|
||||
|
||||
# Store settings
|
||||
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$footprint
|
||||
ynh_app_setting_set --app=$app --key=fpm_usage --value=$usage
|
||||
|
||||
# Define the values to use for the configuration of PHP.
|
||||
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
||||
|
||||
local phpfpm_path="../conf/php-fpm.conf"
|
||||
echo "
|
||||
[__APP__]
|
||||
|
||||
user = __APP__
|
||||
group = __APP__
|
||||
|
||||
chdir = __FINALPATH__
|
||||
|
||||
listen = /var/run/php/php__PHP_VERSION__-fpm-__APP__.sock
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
|
||||
pm = __PHP_PM__
|
||||
pm.max_children = __PHP_MAX_CHILDREN__
|
||||
pm.max_requests = 500
|
||||
request_terminate_timeout = 1d
|
||||
" > $phpfpm_path
|
||||
|
||||
if [ "$php_pm" = "dynamic" ]
|
||||
then
|
||||
echo "
|
||||
pm.start_servers = __PHP_START_SERVERS__
|
||||
pm.min_spare_servers = __PHP_MIN_SPARE_SERVERS__
|
||||
pm.max_spare_servers = __PHP_MAX_SPARE_SERVERS__
|
||||
" >> $phpfpm_path
|
||||
|
||||
elif [ "$php_pm" = "ondemand" ]
|
||||
then
|
||||
echo "
|
||||
pm.process_idle_timeout = 10s
|
||||
" >> $phpfpm_path
|
||||
fi
|
||||
|
||||
# Concatene the extra config.
|
||||
if [ -e ../conf/extra_php-fpm.conf ]; then
|
||||
cat ../conf/extra_php-fpm.conf >> "$phpfpm_path"
|
||||
fi
|
||||
fi
|
||||
|
||||
local finalphpconf="$fpm_config_dir/$app.conf"
|
||||
ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf"
|
||||
|
||||
if [ -e "../conf/php-fpm.ini" ]
|
||||
then
|
||||
ynh_print_warn --message="Packagers ! Please do not use a separate php ini file, merge your directives in the pool file instead."
|
||||
ynh_add_config --template="../conf/php-fpm.ini" --destination="$fpm_config_dir/conf.d/20-$app.ini"
|
||||
fi
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
# Create a dedicated php-fpm.conf for the service
|
||||
local globalphpconf=$fpm_config_dir/php-fpm-$app.conf
|
||||
|
||||
echo "[global]
|
||||
pid = /run/php/php__PHP_VERSION__-fpm-__APP__.pid
|
||||
error_log = /var/log/php/fpm-php.__APP__.log
|
||||
syslog.ident = php-fpm-__APP__
|
||||
include = __FINALPHPCONF__
|
||||
" > ../conf/php-fpm-$app.conf
|
||||
|
||||
ynh_add_config --template="../config/php-fpm-$app.conf" --destination="$globalphpconf"
|
||||
|
||||
# Create a config for a dedicated PHP-FPM service for the app
|
||||
echo "[Unit]
|
||||
Description=PHP __PHP_VERSION__ FastCGI Process Manager for __APP__
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
PIDFile=/run/php/php__PHP_VERSION__-fpm-__APP__.pid
|
||||
ExecStart=__PHP_VERSION_PATH__/__PHP_VERSION__/sbin/php-fpm --nodaemonize --fpm-config __GLOBALPHPCONF__
|
||||
ExecReload=/bin/kill -USR2 \$MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
" > ../conf/$fpm_service
|
||||
|
||||
# Create this dedicated PHP-FPM service
|
||||
ynh_add_systemd_config --service=$fpm_service --template=$fpm_service
|
||||
# Integrate the service in YunoHost admin panel
|
||||
yunohost service add $fpm_service --log /var/log/php/fpm-php.$app.log --log_type file --description "Php-fpm dedicated to $app"
|
||||
# Configure log rotate
|
||||
ynh_use_logrotate --logfile=/var/log/php
|
||||
# Restart the service, as this service is either stopped or only for this app
|
||||
ynh_systemd_action --service_name=$fpm_service --action=restart
|
||||
else
|
||||
# Validate that the new php conf doesn't break php-fpm entirely
|
||||
if ! $php_version_path/$php_version/sbin/php-fpm --test 2>/dev/null
|
||||
then
|
||||
$php_version_path/$php_version/sbin/php-fpm --test || true
|
||||
ynh_secure_remove --file="$finalphpconf"
|
||||
ynh_die --message="The new configuration broke php${php_version}-fpm"
|
||||
fi
|
||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove the dedicated PHP-FPM config
|
||||
#
|
||||
# usage: ynh_remove_fpm_config
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
ynh_remove_fpm_config () {
|
||||
local fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
|
||||
local fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service)
|
||||
local dedicated_service=$(ynh_app_setting_get --app=$app --key=fpm_dedicated_service)
|
||||
dedicated_service=${dedicated_service:-0}
|
||||
# Get the version of PHP used by this app
|
||||
local php_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=php_version)
|
||||
|
||||
# Assume default PHP files if not set
|
||||
if [ -z "$fpm_config_dir" ]
|
||||
then
|
||||
fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
fpm_service="php${php_version}-fpm"
|
||||
fi
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
# Remove the dedicated service PHP-FPM service for the app
|
||||
ynh_remove_systemd_config --service=$fpm_service
|
||||
# Remove the global PHP-FPM conf
|
||||
ynh_secure_remove --file="$fpm_config_dir/php-fpm-$app.conf"
|
||||
# Remove the service from the list of services known by YunoHost
|
||||
yunohost service remove $fpm_service
|
||||
elif ynh_package_is_installed --package="php${phpversion}-fpm"; then
|
||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
||||
fi
|
||||
# Sets the local application-specific PHP version
|
||||
pushd $final_path
|
||||
phpenv local $php_version
|
||||
popd
|
||||
}
|
||||
|
||||
# Install a specific version of PHP
|
||||
|
@ -502,68 +332,238 @@ ynh_cleanup_php () {
|
|||
fi
|
||||
}
|
||||
|
||||
# Load the version of PHP for an app, and set variables.
|
||||
# Create a dedicated PHP-FPM config
|
||||
#
|
||||
# ynh_use_php has to be used in any app scripts before using PHP for the first time.
|
||||
# This helper will provide alias and variables to use in your scripts.
|
||||
# usage 1: ynh_add_fpm_config [--phpversion=7.X] [--use_template] [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion= - Version of PHP to use.
|
||||
# | arg: -t, --use_template - Use this helper in template mode.
|
||||
# | arg: -p, --package= - Additionnal PHP packages to install
|
||||
# | arg: -d, --dedicated_service - Use a dedicated PHP-FPM service instead of the common one.
|
||||
#
|
||||
# To use gem or PHP, use the alias `ynh_gem` and `ynh_php`
|
||||
# Those alias will use the correct version installed for the app
|
||||
# For example: use `ynh_gem install` instead of `gem install`
|
||||
# -----------------------------------------------------------------------------
|
||||
#
|
||||
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_php`
|
||||
# And propagate $PATH to sudo with $ynh_php_load_path
|
||||
# Exemple: `ynh_exec_as $app $ynh_php_load_path $ynh_gem install`
|
||||
# usage 2: ynh_add_fpm_config [--phpversion=7.X] --usage=usage --footprint=footprint [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion= - Version of PHP to use.
|
||||
# | arg: -f, --footprint= - Memory footprint of the service (low/medium/high).
|
||||
# low - Less than 20 MB of RAM by pool.
|
||||
# medium - Between 20 MB and 40 MB of RAM by pool.
|
||||
# high - More than 40 MB of RAM by pool.
|
||||
# Or specify exactly the footprint, the load of the service as MB by pool instead of having a standard value.
|
||||
# To have this value, use the following command and stress the service.
|
||||
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
|
||||
#
|
||||
# $PATH contains the path of the requested version of PHP.
|
||||
# However, $PATH is duplicated into $php_path to outlast any manipulation of $PATH
|
||||
# You can use the variable `$ynh_php_load_path` to quickly load your PHP version
|
||||
# in $PATH for an usage into a separate script.
|
||||
# Exemple: $ynh_php_load_path $final_path/script_that_use_gem.sh`
|
||||
# | arg: -u, --usage= - Expected usage of the service (low/medium/high).
|
||||
# low - Personal usage, behind the SSO.
|
||||
# medium - Low usage, few people or/and publicly accessible.
|
||||
# high - High usage, frequently visited website.
|
||||
#
|
||||
# | arg: -p, --package= - Additionnal PHP packages to install for a specific version of PHP
|
||||
# | arg: -d, --dedicated_service - Use a dedicated PHP-FPM service instead of the common one.
|
||||
#
|
||||
#
|
||||
# Finally, to start a PHP service with the correct version, 2 solutions
|
||||
# Either the app is dependent of PHP or gem, but does not called it directly.
|
||||
# In such situation, you need to load PATH
|
||||
# `Environment="__YNH_PHP_LOAD_ENV_PATH__"`
|
||||
# `ExecStart=__FINALPATH__/my_app`
|
||||
# You will replace __YNH_PHP_LOAD_ENV_PATH__ with $ynh_php_load_path
|
||||
#
|
||||
# Or PHP start the app directly, then you don't need to load the PATH variable
|
||||
# `ExecStart=__YNH_PHP__ my_app run`
|
||||
# You will replace __YNH_PHP__ with $ynh_php
|
||||
#
|
||||
#
|
||||
# one other variable is also available
|
||||
# - $php_path: The absolute path to PHP binaries for the chosen version.
|
||||
#
|
||||
# usage: ynh_use_php
|
||||
#
|
||||
# Requires YunoHost version 2.7.12 or higher.
|
||||
ynh_use_php () {
|
||||
php_version=$(ynh_app_setting_get --app=$app --key=php_version)
|
||||
ynh_add_fpm_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vtufpd
|
||||
local -A args_array=( [v]=phpversion= [t]=use_template [u]=usage= [f]=footprint= [p]=package= [d]=dedicated_service )
|
||||
local phpversion
|
||||
local use_template
|
||||
local usage
|
||||
local footprint
|
||||
local package
|
||||
local dedicated_service
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
package=${package:-}
|
||||
|
||||
# Get the absolute path of this version of PHP
|
||||
php_path="$php_version_path/$php_version/bin"
|
||||
|
||||
# Allow alias to be used into bash script
|
||||
shopt -s expand_aliases
|
||||
|
||||
# Create an alias for the specific version of PHP and a variable as fallback
|
||||
ynh_php="$php_path/php"
|
||||
alias ynh_php="$ynh_php"
|
||||
|
||||
ynh_fpm_conf="$php_version_path/$php_version/etc/php-fpm.d/$YNH_APP_INSTANCE_NAME.conf"
|
||||
|
||||
# Load the path of this version of PHP in $PATH
|
||||
if [[ :$PATH: != *":$php_path"* ]]; then
|
||||
PATH="$php_path:$PATH"
|
||||
# The default behaviour is to use the template.
|
||||
use_template="${use_template:-1}"
|
||||
usage="${usage:-}"
|
||||
footprint="${footprint:-}"
|
||||
if [ -n "$usage" ] || [ -n "$footprint" ]; then
|
||||
use_template=0
|
||||
fi
|
||||
# Create an alias to easily load the PATH
|
||||
ynh_php_load_path="PATH=$PATH"
|
||||
# Do not use a dedicated service by default
|
||||
dedicated_service=${dedicated_service:-0}
|
||||
|
||||
# Sets the local application-specific PHP version
|
||||
pushd $final_path
|
||||
phpenv local $php_version
|
||||
popd
|
||||
phpversion=""
|
||||
local php_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=php_version)
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
local fpm_service="${app}-phpfpm"
|
||||
local fpm_config_dir="$php_version_path/$php_version/etc/dedicated-fpm"
|
||||
else
|
||||
local fpm_service="php${php_version}-fpm"
|
||||
local fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
fi
|
||||
|
||||
# Create the directory for FPM pools
|
||||
mkdir --parents "$fpm_config_dir"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=fpm_config_dir --value="$fpm_config_dir"
|
||||
ynh_app_setting_set --app=$app --key=fpm_service --value="$fpm_service"
|
||||
ynh_app_setting_set --app=$app --key=fpm_dedicated_service --value="$dedicated_service"
|
||||
|
||||
# Migrate from mutual PHP service to dedicated one.
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
local old_fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
# If a config file exist in the common pool, move it.
|
||||
if [ -e "$old_fpm_config_dir/$app.conf" ]
|
||||
then
|
||||
ynh_print_info --message="Migrate to a dedicated php-fpm service for $app."
|
||||
# Create a backup of the old file before migration
|
||||
ynh_backup_if_checksum_is_different --file="$old_fpm_config_dir/$app.conf"
|
||||
# Remove the old PHP config file
|
||||
ynh_secure_remove --file="$old_fpm_config_dir/$app.conf"
|
||||
# Reload PHP to release the socket and allow the dedicated service to use it
|
||||
ynh_systemd_action --service_name=php${php_version}-fpm --action=reload
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $use_template -eq 1 ]
|
||||
then
|
||||
# Usage 1, use the template in conf/php-fpm.conf
|
||||
local phpfpm_path="../conf/php-fpm.conf"
|
||||
# Make sure now that the template indeed exists
|
||||
[ -e "$phpfpm_path" ] || ynh_die --message="Unable to find template to configure PHP-FPM."
|
||||
else
|
||||
# Usage 2, generate a PHP-FPM config file with ynh_get_scalable_phpfpm
|
||||
|
||||
# Store settings
|
||||
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$footprint
|
||||
ynh_app_setting_set --app=$app --key=fpm_usage --value=$usage
|
||||
|
||||
# Define the values to use for the configuration of PHP.
|
||||
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
||||
|
||||
local phpfpm_path="../conf/php-fpm.conf"
|
||||
echo "
|
||||
[__APP__]
|
||||
|
||||
user = __APP__
|
||||
group = __APP__
|
||||
|
||||
chdir = __FINALPATH__
|
||||
|
||||
listen = /var/run/php/php__PHP_VERSION__-fpm-__APP__.sock
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
|
||||
pm = __PHP_PM__
|
||||
pm.max_children = __PHP_MAX_CHILDREN__
|
||||
pm.max_requests = 500
|
||||
request_terminate_timeout = 1d
|
||||
" > $phpfpm_path
|
||||
|
||||
if [ "$php_pm" = "dynamic" ]
|
||||
then
|
||||
echo "
|
||||
pm.start_servers = __PHP_START_SERVERS__
|
||||
pm.min_spare_servers = __PHP_MIN_SPARE_SERVERS__
|
||||
pm.max_spare_servers = __PHP_MAX_SPARE_SERVERS__
|
||||
" >> $phpfpm_path
|
||||
|
||||
elif [ "$php_pm" = "ondemand" ]
|
||||
then
|
||||
echo "
|
||||
pm.process_idle_timeout = 10s
|
||||
" >> $phpfpm_path
|
||||
fi
|
||||
|
||||
# Concatene the extra config.
|
||||
if [ -e ../conf/extra_php-fpm.conf ]; then
|
||||
cat ../conf/extra_php-fpm.conf >> "$phpfpm_path"
|
||||
fi
|
||||
fi
|
||||
|
||||
local finalphpconf="$fpm_config_dir/$app.conf"
|
||||
ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf"
|
||||
|
||||
if [ -e "../conf/php-fpm.ini" ]
|
||||
then
|
||||
ynh_print_warn --message="Packagers ! Please do not use a separate php ini file, merge your directives in the pool file instead."
|
||||
ynh_add_config --template="../conf/php-fpm.ini" --destination="$fpm_config_dir/conf.d/20-$app.ini"
|
||||
fi
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
# Create a dedicated php-fpm.conf for the service
|
||||
local globalphpconf=$fpm_config_dir/php-fpm-$app.conf
|
||||
|
||||
echo "[global]
|
||||
pid = /run/php/php__PHP_VERSION__-fpm-__APP__.pid
|
||||
error_log = /var/log/php/fpm-php.__APP__.log
|
||||
syslog.ident = php-fpm-__APP__
|
||||
include = __FINALPHPCONF__
|
||||
" > ../conf/php-fpm-$app.conf
|
||||
|
||||
ynh_add_config --template="../config/php-fpm-$app.conf" --destination="$globalphpconf"
|
||||
|
||||
# Create a config for a dedicated PHP-FPM service for the app
|
||||
echo "[Unit]
|
||||
Description=PHP __PHP_VERSION__ FastCGI Process Manager for __APP__
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
PIDFile=/run/php/php__PHP_VERSION__-fpm-__APP__.pid
|
||||
ExecStart=__PHP_VERSION_PATH__/__PHP_VERSION__/sbin/php-fpm --nodaemonize --fpm-config __GLOBALPHPCONF__
|
||||
ExecReload=/bin/kill -USR2 \$MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
" > ../conf/$fpm_service
|
||||
|
||||
# Create this dedicated PHP-FPM service
|
||||
ynh_add_systemd_config --service=$fpm_service --template=$fpm_service
|
||||
# Integrate the service in YunoHost admin panel
|
||||
yunohost service add $fpm_service --log /var/log/php/fpm-php.$app.log --log_type file --description "Php-fpm dedicated to $app"
|
||||
# Configure log rotate
|
||||
ynh_use_logrotate --logfile=/var/log/php
|
||||
# Restart the service, as this service is either stopped or only for this app
|
||||
ynh_systemd_action --service_name=$fpm_service --action=restart
|
||||
else
|
||||
# Validate that the new php conf doesn't break php-fpm entirely
|
||||
if ! $php_version_path/$php_version/sbin/php-fpm --test 2>/dev/null
|
||||
then
|
||||
$php_version_path/$php_version/sbin/php-fpm --test || true
|
||||
ynh_secure_remove --file="$finalphpconf"
|
||||
ynh_die --message="The new configuration broke php${php_version}-fpm"
|
||||
fi
|
||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove the dedicated PHP-FPM config
|
||||
#
|
||||
# usage: ynh_remove_fpm_config
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
ynh_remove_fpm_config () {
|
||||
local fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
|
||||
local fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service)
|
||||
local dedicated_service=$(ynh_app_setting_get --app=$app --key=fpm_dedicated_service)
|
||||
dedicated_service=${dedicated_service:-0}
|
||||
# Get the version of PHP used by this app
|
||||
local php_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=php_version)
|
||||
|
||||
# Assume default PHP files if not set
|
||||
if [ -z "$fpm_config_dir" ]
|
||||
then
|
||||
fpm_config_dir="$php_version_path/$php_version/etc/php-fpm.d"
|
||||
fpm_service="php${php_version}-fpm"
|
||||
fi
|
||||
|
||||
if [ $dedicated_service -eq 1 ]
|
||||
then
|
||||
# Remove the dedicated service PHP-FPM service for the app
|
||||
ynh_remove_systemd_config --service=$fpm_service
|
||||
# Remove the global PHP-FPM conf
|
||||
ynh_secure_remove --file="$fpm_config_dir/php-fpm-$app.conf"
|
||||
# Remove the service from the list of services known by YunoHost
|
||||
yunohost service remove $fpm_service
|
||||
elif ynh_package_is_installed --package="php${phpversion}-fpm"; then
|
||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue