helpers2.1: rename everything again, i.e. ynh_{nodejs|ruby|composer|...}_install/remove (to have a proper ynh_{tech}_ prefix like we have for mysql/psql helpers) + same idea for ynh_config_add_{nginx|phpfpm|systemd|...} instead of ynh_add_foo_config

This commit is contained in:
Alexandre Aubin 2024-06-19 17:05:50 +02:00
parent ec354d443d
commit 218bf107fb
12 changed files with 91 additions and 107 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
YNH_INSTALL_APT_DEPENDENCIES_REPLACE="true" YNH_APT_INSTALL_DEPENDENCIES_REPLACE="true"
# Define and install dependencies with a equivs control file # Define and install dependencies with a equivs control file
# #
@ -15,7 +15,7 @@ YNH_INSTALL_APT_DEPENDENCIES_REPLACE="true"
# | arg: "dep1|dep2|…" - You can specify alternatives. It will require to install (dep1 or dep2, etc). # | arg: "dep1|dep2|…" - You can specify alternatives. It will require to install (dep1 or dep2, etc).
# #
# Requires YunoHost version 2.6.4 or higher. # Requires YunoHost version 2.6.4 or higher.
ynh_install_apt_dependencies() { ynh_apt_install_dependencies() {
local dependencies=$@ local dependencies=$@
# Add a comma for each space between packages. But not add a comma if the space separate a version specification. (See below) # Add a comma for each space between packages. But not add a comma if the space separate a version specification. (See below)
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
@ -86,9 +86,9 @@ ynh_install_apt_dependencies() {
# upgrade script where ynh_install_app_dependencies is called with this # upgrade script where ynh_install_app_dependencies is called with this
# expected effect) Otherwise, any subsequent call will add dependencies # expected effect) Otherwise, any subsequent call will add dependencies
# to those already present in the equivs control file. # to those already present in the equivs control file.
if [[ $YNH_INSTALL_APT_DEPENDENCIES_REPLACE == "true" ]] if [[ $YNH_APT_INSTALL_DEPENDENCIES_REPLACE == "true" ]]
then then
YNH_INSTALL_APT_DEPENDENCIES_REPLACE="false" YNH_APT_INSTALL_DEPENDENCIES_REPLACE="false"
else else
local current_dependencies="" local current_dependencies=""
if _ynh_apt_package_is_installed "${app_ynh_deps}" if _ynh_apt_package_is_installed "${app_ynh_deps}"
@ -165,10 +165,10 @@ EOF
# #
# Dependencies will removed only if no other package need them. # Dependencies will removed only if no other package need them.
# #
# usage: ynh_remove_apt_dependencies # usage: ynh_apt_remove_dependencies
# #
# Requires YunoHost version 2.6.4 or higher. # Requires YunoHost version 2.6.4 or higher.
ynh_remove_apt_dependencies() { ynh_apt_remove_dependencies() {
local app_ynh_deps="${app//_/-}-ynh-deps" # Replace all '_' by '-', and append -ynh-deps local app_ynh_deps="${app//_/-}-ynh-deps" # Replace all '_' by '-', and append -ynh-deps
local current_dependencies="" local current_dependencies=""
@ -197,13 +197,13 @@ ynh_remove_apt_dependencies() {
# #
# [packagingv1] # [packagingv1]
# #
# usage: ynh_install_extra_apt_dependencies --repo="repo" --package="dep1 dep2" --key=key_url # usage: ynh_apt_install_dependencies_from_extra_repository --repo="repo" --package="dep1 dep2" --key=key_url
# | arg: -r, --repo= - Complete url of the extra repository. # | arg: -r, --repo= - Complete url of the extra repository.
# | arg: -p, --package= - The packages to install from this extra repository # | arg: -p, --package= - The packages to install from this extra repository
# | arg: -k, --key= - url to get the public key. # | arg: -k, --key= - url to get the public key.
# #
# Requires YunoHost version 3.8.1 or higher. # Requires YunoHost version 3.8.1 or higher.
ynh_install_extra_apt_dependencies() { ynh_apt_install_dependencies_from_extra_repository() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([r]=repo= [p]=package= [k]=key=) local -A args_array=([r]=repo= [p]=package= [k]=key=)
local repo local repo
@ -241,16 +241,16 @@ EOF
# Update the list of package with the new repo NB: we use -o # Update the list of package with the new repo NB: we use -o
# Dir::Etc::sourcelist to only refresh this repo, because # Dir::Etc::sourcelist to only refresh this repo, because
# ynh_install_apt_dependencies will also call an ynh_apt update on its own # ynh_apt_install_dependencies will also call an ynh_apt update on its own
# and it's good to limit unecessary requests ... Here we mainly want to # and it's good to limit unecessary requests ... Here we mainly want to
# validate that the url+key is correct before going further # validate that the url+key is correct before going further
_ynh_apt update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/$app.list" _ynh_apt update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/$app.list"
# Install requested dependencies from this extra repository. # Install requested dependencies from this extra repository.
# NB: because of the mechanism with $YNH_INSTALL_APT_DEPENDENCIES_REPLACE, # NB: because of the mechanism with $ynh_apt_install_DEPENDENCIES_REPLACE,
# this will usually only *append* to the existing list of dependency, not # this will usually only *append* to the existing list of dependency, not
# replace the existing $app-ynh-deps # replace the existing $app-ynh-deps
ynh_install_apt_dependencies "$package" ynh_apt_install_dependencies "$package"
# Force to upgrade to the last version... # Force to upgrade to the last version...
# Without doing apt install, an already installed dep is not upgraded # Without doing apt install, an already installed dep is not upgraded

View file

@ -307,12 +307,3 @@ ynh_delete_file_checksum() {
local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete --key=$checksum_setting_name ynh_app_setting_delete --key=$checksum_setting_name
} }
# Checks a backup archive exists
#
# [internal]
#
ynh_backup_archive_exists() {
yunohost backup list --output-as json --quiet \
| jq -e --arg archive "$1" '.archives | index($archive)' >/dev/null
}

View file

@ -2,15 +2,15 @@
# Create a dedicated fail2ban config (jail and filter conf files) # Create a dedicated fail2ban config (jail and filter conf files)
# #
# usage 1: ynh_add_fail2ban_config --logpath=log_file --failregex=filter # usage 1: ynh_config_add_fail2ban --logpath=log_file --failregex=filter
# | arg: -l, --logpath= - Log file to be checked by fail2ban # | arg: -l, --logpath= - Log file to be checked by fail2ban
# | arg: -r, --failregex= - Failregex to be looked for by fail2ban # | arg: -r, --failregex= - Failregex to be looked for by fail2ban
# #
# usage 2: ynh_add_fail2ban_config # usage 2: ynh_config_add_fail2ban
# | arg: -t, --use_template - Use this helper in template mode # | arg: -t, --use_template - Use this helper in template mode
# #
# This will use a template in `../conf/f2b_jail.conf` and `../conf/f2b_filter.conf` # This will use a template in `../conf/f2b_jail.conf` and `../conf/f2b_filter.conf`
# See the documentation of `ynh_add_config` for a description of the template # See the documentation of `ynh_config_add` for a description of the template
# format and how placeholders are replaced with actual variables. # format and how placeholders are replaced with actual variables.
# #
# Generally your template will look like that by example (for synapse): # Generally your template will look like that by example (for synapse):
@ -55,7 +55,7 @@
# ``` # ```
# #
# Requires YunoHost version 4.1.0 or higher. # Requires YunoHost version 4.1.0 or higher.
ynh_add_fail2ban_config() { ynh_config_add_fail2ban() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([l]=logpath= [r]=failregex=) local -A args_array=([l]=logpath= [r]=failregex=)
local logpath local logpath
@ -65,7 +65,7 @@ ynh_add_fail2ban_config() {
# If failregex is provided, Build a config file on-the-fly using $logpath and $failregex # If failregex is provided, Build a config file on-the-fly using $logpath and $failregex
if [[ -n "${failregex:-}" ]]; then if [[ -n "${failregex:-}" ]]; then
test -n "$logpath" || ynh_die --message="ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." test -n "$logpath" || ynh_die --message="ynh_config_add_fail2ban expects a logfile path as first argument and received nothing."
echo " echo "
[__APP__] [__APP__]
@ -85,8 +85,8 @@ ignoreregex =
" >"$YNH_APP_BASEDIR/conf/f2b_filter.conf" " >"$YNH_APP_BASEDIR/conf/f2b_filter.conf"
fi fi
ynh_add_config --template="f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf" ynh_config_add --template="f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf"
ynh_add_config --template="f2b_filter.conf" --destination="/etc/fail2ban/filter.d/$app.conf" ynh_config_add --template="f2b_filter.conf" --destination="/etc/fail2ban/filter.d/$app.conf"
# if "$logpath" doesn't exist (as if using --use_template argument), assign # if "$logpath" doesn't exist (as if using --use_template argument), assign
# "$logpath" using the one in the previously generated fail2ban conf file # "$logpath" using the one in the previously generated fail2ban conf file
@ -116,10 +116,10 @@ ignoreregex =
# Remove the dedicated fail2ban config (jail and filter conf files) # Remove the dedicated fail2ban config (jail and filter conf files)
# #
# usage: ynh_remove_fail2ban_config # usage: ynh_config_remove_fail2ban
# #
# Requires YunoHost version 3.5.0 or higher. # Requires YunoHost version 3.5.0 or higher.
ynh_remove_fail2ban_config() { ynh_config_remove_fail2ban() {
ynh_safe_rm "/etc/fail2ban/jail.d/$app.conf" ynh_safe_rm "/etc/fail2ban/jail.d/$app.conf"
ynh_safe_rm "/etc/fail2ban/filter.d/$app.conf" ynh_safe_rm "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --service=fail2ban --action=reload ynh_systemd_action --service=fail2ban --action=reload

View file

@ -48,12 +48,12 @@ _ynh_load_go_in_path_and_other_tweaks() {
# When not possible (e.g. in systemd service definition), please use direct path # When not possible (e.g. in systemd service definition), please use direct path
# to goenv shims (e.g. $goenv_ROOT/shims/bundle) # to goenv shims (e.g. $goenv_ROOT/shims/bundle)
# #
# usage: ynh_install_go # usage: ynh_go_install
# #
# Requires YunoHost version 3.2.2 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_install_go () { ynh_go_install () {
[[ -n "${go_version:-}" ]] || ynh_die --message="\$go_version should be defined prior to calling ynh_install_go" [[ -n "${go_version:-}" ]] || ynh_die --message="\$go_version should be defined prior to calling ynh_go_install"
# Load goenv path in PATH # Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH" local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
@ -118,7 +118,7 @@ ynh_install_go () {
go_version=$final_go_version go_version=$final_go_version
# Cleanup Go versions # Cleanup Go versions
ynh_cleanup_go _ynh_go_cleanup
# Set environment for Go users # Set environment for Go users
echo "#goenv echo "#goenv
@ -137,8 +137,8 @@ eval \"\$(goenv init -)\"
# #
# This helper will also cleanup Go versions # This helper will also cleanup Go versions
# #
# usage: ynh_remove_go # usage: ynh_go_remove
ynh_remove_go () { ynh_go_remove () {
local go_version=$(ynh_app_setting_get --key="go_version") local go_version=$(ynh_app_setting_get --key="go_version")
# Load goenv path in PATH # Load goenv path in PATH
@ -151,7 +151,7 @@ ynh_remove_go () {
ynh_app_setting_delete --key="go_version" ynh_app_setting_delete --key="go_version"
# Cleanup Go versions # Cleanup Go versions
ynh_cleanup_go _ynh_go_cleanup
} }
# Remove no more needed versions of Go used by the app. # Remove no more needed versions of Go used by the app.
@ -160,8 +160,8 @@ ynh_remove_go () {
# and uninstall them # and uninstall them
# If no app uses Go, goenv will be also removed. # If no app uses Go, goenv will be also removed.
# #
# usage: ynh_cleanup_go # usage: _ynh_go_cleanup
ynh_cleanup_go () { _ynh_go_cleanup () {
# List required Go versions # List required Go versions
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id) local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)

View file

@ -4,7 +4,7 @@ FIRST_CALL_TO_LOGROTATE="true"
# Add a logrotate configuration to manage log files / log directory # Add a logrotate configuration to manage log files / log directory
# #
# usage: ynh_add_logrotate_config [/path/to/log/file/or/folder] # usage: ynh_config_add_logrotate [/path/to/log/file/or/folder]
# #
# If not argument is provided, `/var/log/$app/*.log` is used as default. # If not argument is provided, `/var/log/$app/*.log` is used as default.
# #
@ -12,7 +12,7 @@ FIRST_CALL_TO_LOGROTATE="true"
# (ie it doesnt come from a specific app template like nginx or systemd conf) # (ie it doesnt come from a specific app template like nginx or systemd conf)
# #
# Requires YunoHost version 2.6.4 or higher. # Requires YunoHost version 2.6.4 or higher.
ynh_add_logrotate_config() { ynh_config_add_logrotate() {
logfile="$1" logfile="$1"
@ -70,7 +70,7 @@ EOF
# usage: ynh_remove_logrotate # usage: ynh_remove_logrotate
# #
# Requires YunoHost version 2.6.4 or higher. # Requires YunoHost version 2.6.4 or higher.
ynh_remove_logrotate_config() { ynh_config_remove_logrotate() {
if [ -e "/etc/logrotate.d/$app" ]; then if [ -e "/etc/logrotate.d/$app" ]; then
rm "/etc/logrotate.d/$app" rm "/etc/logrotate.d/$app"
fi fi

View file

@ -2,13 +2,13 @@
# Create a dedicated nginx config # Create a dedicated nginx config
# #
# usage: ynh_add_nginx_config # usage: ynh_config_add_nginx
# #
# This will use a template in `../conf/nginx.conf` # This will use a template in `../conf/nginx.conf`
# See the documentation of `ynh_add_config` for a description of the template # See the documentation of `ynh_config_add` for a description of the template
# format and how placeholders are replaced with actual variables. # format and how placeholders are replaced with actual variables.
# #
# Additionally, ynh_add_nginx_config will replace: # Additionally, ynh_config_add_nginx will replace:
# - `#sub_path_only` by empty string if `path` is not `'/'` # - `#sub_path_only` by empty string if `path` is not `'/'`
# - `#root_path_only` by empty string if `path` *is* `'/'` # - `#root_path_only` by empty string if `path` *is* `'/'`
# #
@ -16,11 +16,11 @@
# location # location
# #
# Requires YunoHost version 4.1.0 or higher. # Requires YunoHost version 4.1.0 or higher.
ynh_add_nginx_config() { ynh_config_add_nginx() {
local finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" local finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_add_config --template="nginx.conf" --destination="$finalnginxconf" ynh_config_add --template="nginx.conf" --destination="$finalnginxconf"
if [ "${path:-}" != "/" ]; then if [ "${path:-}" != "/" ]; then
ynh_replace --match="^#sub_path_only" --replace="" --file="$finalnginxconf" ynh_replace --match="^#sub_path_only" --replace="" --file="$finalnginxconf"
@ -35,10 +35,10 @@ ynh_add_nginx_config() {
# Remove the dedicated nginx config # Remove the dedicated nginx config
# #
# usage: ynh_remove_nginx_config # usage: ynh_config_remove_nginx
# #
# Requires YunoHost version 2.7.2 or higher. # Requires YunoHost version 2.7.2 or higher.
ynh_remove_nginx_config() { ynh_config_remove_nginx() {
ynh_safe_rm "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_safe_rm "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service=nginx --action=reload ynh_systemd_action --service=nginx --action=reload
} }
@ -46,14 +46,14 @@ ynh_remove_nginx_config() {
# Regen the nginx config in a change url context # Regen the nginx config in a change url context
# #
# usage: ynh_change_url_nginx_config # usage: ynh_config_change_url_nginx
# #
# Requires YunoHost version 11.1.9 or higher. # Requires YunoHost version 11.1.9 or higher.
ynh_change_url_nginx_config() { ynh_config_change_url_nginx() {
# Make a backup of the original NGINX config file if manually modified # Make a backup of the original NGINX config file if manually modified
# (nb: this is possibly different from the same instruction called by # (nb: this is possibly different from the same instruction called by
# ynh_add_config inside ynh_add_nginx_config because the path may have # ynh_config_add inside ynh_config_add_nginx because the path may have
# changed if we're changing the domain too...) # changed if we're changing the domain too...)
local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path" ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
@ -61,5 +61,5 @@ ynh_change_url_nginx_config() {
ynh_safe_rm "$old_nginx_conf_path" ynh_safe_rm "$old_nginx_conf_path"
# Regen the nginx conf # Regen the nginx conf
ynh_add_nginx_config ynh_config_add_nginx
} }

View file

@ -30,7 +30,7 @@ _ynh_load_nodejs_in_path_and_other_tweaks() {
# #
# The installed version is defined by $nodejs_version which should be defined as global prior to calling this helper # The installed version is defined by $nodejs_version which should be defined as global prior to calling this helper
# #
# usage: ynh_install_nodejs # usage: ynh_nodejs_install
# #
# `n` (Node version management) uses the `PATH` variable to store the path of the version of node it is going to use. # `n` (Node version management) uses the `PATH` variable to store the path of the version of node it is going to use.
# That's how it changes the version # That's how it changes the version
@ -41,10 +41,10 @@ _ynh_load_nodejs_in_path_and_other_tweaks() {
# (Environment="PATH=__PATH_WITH_NODEJS__") # (Environment="PATH=__PATH_WITH_NODEJS__")
# #
# Requires YunoHost version 2.7.12 or higher. # Requires YunoHost version 2.7.12 or higher.
ynh_install_nodejs() { ynh_nodejs_install() {
# Use n, https://github.com/tj/n to manage the nodejs versions # Use n, https://github.com/tj/n to manage the nodejs versions
[[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_nodejs_install"
# Create $n_install_dir # Create $n_install_dir
mkdir --parents "$n_install_dir" mkdir --parents "$n_install_dir"
@ -95,23 +95,23 @@ ynh_install_nodejs() {
ynh_app_setting_set --key=nodejs_version --value=$nodejs_version ynh_app_setting_set --key=nodejs_version --value=$nodejs_version
# Build the update script and set the cronjob # Build the update script and set the cronjob
ynh_cron_upgrade_node _ynh_cron_upgrade_node
_ynh_load_nodejs_in_path_and_other_tweaks _ynh_load_nodejs_in_path_and_other_tweaks
} }
# Remove the version of node used by the app. # Remove the version of node used by the app.
# #
# usage: ynh_remove_nodejs # usage: ynh_nodejs_remove
# #
# This helper will check if another app uses the same version of node. # This helper will check if another app uses the same version of node.
# - If not, this version of node will be removed. # - If not, this version of node will be removed.
# - If no other app uses node, n will be also removed. # - If no other app uses node, n will be also removed.
# #
# Requires YunoHost version 2.7.12 or higher. # Requires YunoHost version 2.7.12 or higher.
ynh_remove_nodejs() { ynh_nodejs_remove() {
[[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_nodejs_remove"
# Remove the line for this app # Remove the line for this app
sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version" sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version"
@ -136,10 +136,10 @@ ynh_remove_nodejs() {
# #
# This cron will check and update all minor node versions used by your apps. # This cron will check and update all minor node versions used by your apps.
# #
# usage: ynh_cron_upgrade_node # usage: _ynh_cron_upgrade_node
# #
# Requires YunoHost version 2.7.12 or higher. # Requires YunoHost version 2.7.12 or higher.
ynh_cron_upgrade_node() { _ynh_cron_upgrade_node() {
# Build the update script # Build the update script
cat >"$n_install_dir/node_update.sh" <<EOF cat >"$n_install_dir/node_update.sh" <<EOF
#!/bin/bash #!/bin/bash

View file

@ -17,7 +17,7 @@ fi
# Create a dedicated PHP-FPM config # Create a dedicated PHP-FPM config
# #
# usage: ynh_add_fpm_config # usage: ynh_config_add_phpfpm
# #
# This helper assumes the app has an conf/extra_php-fpm.conf snippet # This helper assumes the app has an conf/extra_php-fpm.conf snippet
# #
@ -58,7 +58,7 @@ fi
# children ready to answer. # children ready to answer.
# #
# Requires YunoHost version 4.1.0 or higher. # Requires YunoHost version 4.1.0 or higher.
ynh_add_fpm_config() { ynh_config_add_phpfpm() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([g]=group=) local -A args_array=([g]=group=)
local group local group
@ -68,6 +68,7 @@ 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)
# FIXME: so is this still needed @_@
local old_php_version=$(ynh_app_setting_get --key=php_version) local old_php_version=$(ynh_app_setting_get --key=php_version)
if [ -n "$old_php_version" ] && [ "$old_php_version" != "$php_version" ]; 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)
@ -86,12 +87,13 @@ ynh_add_fpm_config() {
# 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"
# FIXME: zzzz do we really need those ...
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=php_version --value=$php_version 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
local phpfpm_group=$([[ -n "$group" ]] && echo "$group" || echo "$app") local phpfpm_group=$([[ -n "$group" ]] && echo "$group" || echo "$app")
local phpfpm_path="$YNH_APP_BASEDIR/conf/php-fpm.conf" local phpfpm_path="$YNH_APP_BASEDIR/conf/php-fpm.conf"
@ -131,13 +133,12 @@ pm.process_idle_timeout = 10s
cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >>"$phpfpm_path" cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >>"$phpfpm_path"
fi fi
local finalphpconf="$fpm_config_dir/pool.d/$app.conf" ynh_config_add --template="$phpfpm_path" --destination="$fpm_config_dir/pool.d/$app.conf"
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${php_version} --test 2>/dev/null; then if ! php-fpm${php_version} --test 2>/dev/null; then
php-fpm${php_version} --test || true php-fpm${php_version} --test || true
ynh_safe_rm "$finalphpconf" ynh_safe_rm "$fpm_config_dir/pool.d/$app.conf"
ynh_die --message="The new configuration broke php-fpm?" ynh_die --message="The new configuration broke php-fpm?"
fi fi
ynh_systemd_action --service=$fpm_service --action=reload ynh_systemd_action --service=$fpm_service --action=reload
@ -145,22 +146,21 @@ pm.process_idle_timeout = 10s
# Remove the dedicated PHP-FPM config # Remove the dedicated PHP-FPM config
# #
# usage: ynh_remove_fpm_config # usage: ynh_config_remove_phpfpm
# #
# Requires YunoHost version 2.7.2 or higher. # Requires YunoHost version 2.7.2 or higher.
ynh_remove_fpm_config() { ynh_config_remove_phpfpm() {
local fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir) local fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir)
local fpm_service=$(ynh_app_setting_get --key=fpm_service)
ynh_safe_rm "$fpm_config_dir/pool.d/$app.conf" ynh_safe_rm "$fpm_config_dir/pool.d/$app.conf"
ynh_systemd_action --service=$fpm_service --action=reload ynh_systemd_action --service="php${php_version}-fpm" --action=reload
} }
# Define the values to configure PHP-FPM # Define the values to configure PHP-FPM
# #
# [internal] # [internal]
# #
# usage: ynh_get_scalable_phpfpm # usage: _ynh_get_scalable_phpfpm
# Footprint can be defined via the "fpm_footprint", to be set prior to calling this helper # Footprint can be defined via the "fpm_footprint", to be set prior to calling this helper
# low - Less than 20 MB of RAM by pool. # low - Less than 20 MB of RAM by pool.
# medium - Between 20 MB and 40 MB of RAM by pool. # medium - Between 20 MB and 40 MB of RAM by pool.
@ -174,7 +174,7 @@ ynh_remove_fpm_config() {
# medium - Low usage, few people or/and publicly accessible. # medium - Low usage, few people or/and publicly accessible.
# high - High usage, frequently visited website. # high - High usage, frequently visited website.
# #
ynh_get_scalable_phpfpm() { _ynh_get_scalable_phpfpm() {
# If no usage provided, default to the value existing in setting ... or to low # If no usage provided, default to the value existing in setting ... or to low
local fpm_usage_in_setting=$(ynh_app_setting_get --key=fpm_usage) local fpm_usage_in_setting=$(ynh_app_setting_get --key=fpm_usage)
@ -294,12 +294,12 @@ ynh_composer_exec() {
# #
# The installed version is defined by $composer_version which should be defined as global prior to calling this helper # The installed version is defined by $composer_version which should be defined as global prior to calling this helper
# #
# usage: ynh_install_composer [--workdir=$install_dir] [--install_args="--optimize-autoloader"] # usage: ynh_composer_install [--workdir=$install_dir] [--install_args="--optimize-autoloader"]
# | arg: -w, --workdir - The directory from where the command will be executed. Default $install_dir. # | arg: -w, --workdir - The directory from where the command will be executed. Default $install_dir.
# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include # | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include
# #
# Requires YunoHost version 4.2 or higher. # Requires YunoHost version 4.2 or higher.
ynh_install_composer() { ynh_composer_install() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([w]=workdir= [a]=install_args=) local -A args_array=([w]=workdir= [a]=install_args=)
local workdir local workdir
@ -309,7 +309,7 @@ ynh_install_composer() {
install_args="${install_args:-}" install_args="${install_args:-}"
# =========================================== # ===========================================
[[ -n "${composer_version}" ]] || ynh_die --message="\$composer_version should be defined before calling ynh_install_composer. (In the past, this was called \$YNH_COMPOSER_VERSION)" [[ -n "${composer_version}" ]] || ynh_die --message="\$composer_version should be defined before calling ynh_composer_install. (In the past, this was called \$YNH_COMPOSER_VERSION)"
[[ ! -e "$workdir/composer.phar" ]] || ynh_safe_rm $workdir/composer.phar [[ ! -e "$workdir/composer.phar" ]] || ynh_safe_rm $workdir/composer.phar

View file

@ -42,7 +42,7 @@ _ynh_load_ruby_in_path_and_other_tweaks() {
# When not possible (e.g. in systemd service definition), please use direct path # When not possible (e.g. in systemd service definition), please use direct path
# to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) # to rbenv shims (e.g. $RBENV_ROOT/shims/bundle)
# #
# usage: ynh_install_ruby # usage: ynh_ruby_install
# #
# Adds the appropriate, specific version of ruby to the PATH variable (which # Adds the appropriate, specific version of ruby to the PATH variable (which
# is also exported, to ease the use of ynh_exec_as_app). Also define variable # is also exported, to ease the use of ynh_exec_as_app). Also define variable
@ -50,9 +50,9 @@ _ynh_load_ruby_in_path_and_other_tweaks() {
# (Environment="PATH=__PATH_WITH_RUBY__") # (Environment="PATH=__PATH_WITH_RUBY__")
# #
# Requires YunoHost version 3.2.2 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_install_ruby () { ynh_ruby_install () {
[[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_install_ruby" [[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_ruby_install"
# Load rbenv path in PATH # Load rbenv path in PATH
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
@ -171,7 +171,7 @@ ynh_install_ruby () {
rbenv alias $app $final_ruby_version rbenv alias $app $final_ruby_version
# Cleanup Ruby versions # Cleanup Ruby versions
ynh_cleanup_ruby _ynh_ruby_cleanup
# Set environment for Ruby users # Set environment for Ruby users
echo "#rbenv echo "#rbenv
@ -183,15 +183,15 @@ eval \"\$(rbenv init -)\"
# Load the environment # Load the environment
eval "$(rbenv init -)" eval "$(rbenv init -)"
_ynh_load_ruby_in_path_and_other_variable_tweaks _ynh_load_ruby_in_path_and_other_tweaks
} }
# Remove the version of Ruby used by the app. # Remove the version of Ruby used by the app.
# #
# This helper will also cleanup Ruby versions # This helper will also cleanup Ruby versions
# #
# usage: ynh_remove_ruby # usage: ynh_ruby_remove
ynh_remove_ruby () { ynh_ruby_remove () {
local ruby_version=$(ynh_app_setting_get --key=ruby_version) local ruby_version=$(ynh_app_setting_get --key=ruby_version)
# Load rbenv path in PATH # Load rbenv path in PATH
@ -206,7 +206,7 @@ ynh_remove_ruby () {
ynh_app_setting_delete --key=ruby_version ynh_app_setting_delete --key=ruby_version
# Cleanup Ruby versions # Cleanup Ruby versions
ynh_cleanup_ruby _ynh_ruby_cleanup
} }
# Remove no more needed versions of Ruby used by the app. # Remove no more needed versions of Ruby used by the app.
@ -214,9 +214,7 @@ ynh_remove_ruby () {
# This helper will check what Ruby version are no more required, # This helper will check what Ruby version are no more required,
# and uninstall them # and uninstall them
# If no app uses Ruby, rbenv will be also removed. # If no app uses Ruby, rbenv will be also removed.
# _ynh_ruby_cleanup () {
# usage: ynh_cleanup_ruby
ynh_cleanup_ruby () {
# List required Ruby versions # List required Ruby versions
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')

View file

@ -2,17 +2,17 @@
# Create a dedicated systemd config # Create a dedicated systemd config
# #
# usage: ynh_add_systemd_config [--service=service] [--template=template] # usage: ynh_config_add_systemd [--service=service] [--template=template]
# | arg: -s, --service= - Service name (optionnal, `$app` by default) # | arg: -s, --service= - Service name (optionnal, `$app` by default)
# | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning `../conf/systemd.service` will be used as template) # | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning `../conf/systemd.service` will be used as template)
# #
# This will use the template `../conf/<templatename>.service`. # This will use the template `../conf/<templatename>.service`.
# #
# See the documentation of `ynh_add_config` for a description of the template # See the documentation of `ynh_config_add` for a description of the template
# format and how placeholders are replaced with actual variables. # format and how placeholders are replaced with actual variables.
# #
# Requires YunoHost version 4.1.0 or higher. # Requires YunoHost version 4.1.0 or higher.
ynh_add_systemd_config() { ynh_config_add_systemd() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([s]=service= [t]=template=) local -A args_array=([s]=service= [t]=template=)
local service local service
@ -22,7 +22,7 @@ ynh_add_systemd_config() {
template="${template:-systemd.service}" template="${template:-systemd.service}"
# =========================================== # ===========================================
ynh_add_config --template="$template" --destination="/etc/systemd/system/$service.service" ynh_config_add --template="$template" --destination="/etc/systemd/system/$service.service"
systemctl enable $service --quiet systemctl enable $service --quiet
systemctl daemon-reload systemctl daemon-reload
@ -30,11 +30,11 @@ ynh_add_systemd_config() {
# Remove the dedicated systemd config # Remove the dedicated systemd config
# #
# usage: ynh_remove_systemd_config [--service=service] # usage: ynh_config_remove_systemd [--service=service]
# | arg: -s, --service= - Service name (optionnal, $app by default) # | arg: -s, --service= - Service name (optionnal, $app by default)
# #
# Requires YunoHost version 2.7.2 or higher. # Requires YunoHost version 2.7.2 or higher.
ynh_remove_systemd_config() { ynh_config_remove_systemd() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([s]=service=) local -A args_array=([s]=service=)
local service local service
@ -117,7 +117,7 @@ ynh_systemd_action() {
if [ -e "$log_path" ]; then if [ -e "$log_path" ]; then
tail --lines=$length "$log_path" >&2 tail --lines=$length "$log_path" >&2
fi fi
ynh_clean_check_starting _ynh_clean_check_starting
return 1 return 1
fi fi
@ -166,16 +166,11 @@ ynh_systemd_action() {
tail --lines=$length "$log_path" >&2 tail --lines=$length "$log_path" >&2
fi fi
fi fi
ynh_clean_check_starting _ynh_clean_check_starting
fi fi
} }
# Clean temporary process and file used by ynh_check_starting _ynh_clean_check_starting() {
#
# [internal]
#
# Requires YunoHost version 3.5.0 or higher.
ynh_clean_check_starting() {
if [ -n "${pid_tail:-}" ]; then if [ -n "${pid_tail:-}" ]; then
# Stop the execution of tail. # Stop the execution of tail.
kill -SIGTERM $pid_tail 2>&1 kill -SIGTERM $pid_tail 2>&1

View file

@ -2,15 +2,15 @@
# Create a dedicated config file from a template # Create a dedicated config file from a template
# #
# usage: ynh_add_config --template="template" --destination="destination" # usage: ynh_config_add --template="template" --destination="destination"
# | arg: -t, --template= - Template config file to use # | arg: -t, --template= - Template config file to use
# | arg: -d, --destination= - Destination of the config file # | arg: -d, --destination= - Destination of the config file
# | arg: -j, --jinja - Use jinja template instead of legacy __MY_VAR__ # | arg: -j, --jinja - Use jinja template instead of legacy __MY_VAR__
# #
# examples: # examples:
# ynh_add_config --template=".env" --destination="$install_dir/.env" use the template file "../conf/.env" # ynh_config_add --template=".env" --destination="$install_dir/.env" use the template file "../conf/.env"
# ynh_add_config --jinja --template="config.j2" --destination="$install_dir/config" use the template file "../conf/config.j2" # ynh_config_add --jinja --template="config.j2" --destination="$install_dir/config" use the template file "../conf/config.j2"
# ynh_add_config --template="/etc/nginx/sites-available/default" --destination="etc/nginx/sites-available/mydomain.conf" # ynh_config_add --template="/etc/nginx/sites-available/default" --destination="etc/nginx/sites-available/mydomain.conf"
# #
## ##
## How it works in "legacy" mode ## How it works in "legacy" mode
@ -72,7 +72,7 @@
# into the app settings when configuration is done. # into the app settings when configuration is done.
# #
# Requires YunoHost version 4.1.0 or higher. # Requires YunoHost version 4.1.0 or higher.
ynh_add_config() { ynh_config_add() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([t]=template= [d]=destination= [j]=jinja) local -A args_array=([t]=template= [d]=destination= [j]=jinja)
local template local template

View file

@ -504,7 +504,7 @@ ynh_app_upgrading_from_version_before_or_equal_to() {
} }
# Check if we should enforce sane default permissions (= disable rwx for 'others') # Check if we should enforce sane default permissions (= disable rwx for 'others')
# on file/folders handled with ynh_setup_source and ynh_add_config # on file/folders handled with ynh_setup_source and ynh_config_add
# #
# [internal] # [internal]
# #