mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #1172 from YunoHost/fix_ynh_add_config_basedir
Define YNH_APP_BASEDIR to be able to properly point to conf folder depending on the app script we're running
This commit is contained in:
commit
5ba94f4add
6 changed files with 25 additions and 35 deletions
|
@ -87,7 +87,7 @@ port = __PORTS__
|
||||||
filter = __APP__
|
filter = __APP__
|
||||||
logpath = __LOGPATH__
|
logpath = __LOGPATH__
|
||||||
maxretry = __MAX_RETRY__
|
maxretry = __MAX_RETRY__
|
||||||
" > ../conf/f2b_jail.conf
|
" > $YNH_APP_BASEDIR/conf/f2b_jail.conf
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
[INCLUDES]
|
[INCLUDES]
|
||||||
|
@ -95,11 +95,11 @@ before = common.conf
|
||||||
[Definition]
|
[Definition]
|
||||||
failregex = __FAILREGEX__
|
failregex = __FAILREGEX__
|
||||||
ignoreregex =
|
ignoreregex =
|
||||||
" > ../conf/f2b_filter.conf
|
" > $YNH_APP_BASEDIR/conf/f2b_filter.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_add_config --template="../conf/f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf"
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf"
|
||||||
ynh_add_config --template="../conf/f2b_filter.conf" --destination="/etc/fail2ban/filter.d/$app.conf"
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/f2b_filter.conf" --destination="/etc/fail2ban/filter.d/$app.conf"
|
||||||
|
|
||||||
ynh_systemd_action --service_name=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
ynh_systemd_action --service_name=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@ ynh_add_nginx_config () {
|
||||||
|
|
||||||
if [ "${path_url:-}" != "/" ]
|
if [ "${path_url:-}" != "/" ]
|
||||||
then
|
then
|
||||||
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
|
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="$YNH_APP_BASEDIR/conf/nginx.conf"
|
||||||
else
|
else
|
||||||
ynh_replace_string --match_string="^#root_path_only" --replace_string="" --target_file="../conf/nginx.conf"
|
ynh_replace_string --match_string="^#root_path_only" --replace_string="" --target_file="$YNH_APP_BASEDIR/conf/nginx.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_add_config --template="../conf/nginx.conf" --destination="$finalnginxconf"
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/nginx.conf" --destination="$finalnginxconf"
|
||||||
|
|
||||||
|
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
|
@ -153,10 +153,7 @@ ynh_add_fpm_config () {
|
||||||
if [ $use_template -eq 1 ]
|
if [ $use_template -eq 1 ]
|
||||||
then
|
then
|
||||||
# Usage 1, use the template in conf/php-fpm.conf
|
# Usage 1, use the template in conf/php-fpm.conf
|
||||||
local phpfpm_path="../conf/php-fpm.conf"
|
local phpfpm_path="$YNH_APP_BASEDIR/conf/php-fpm.conf"
|
||||||
if [ ! -e "$phpfpm_path" ]; then
|
|
||||||
phpfpm_path="../settings/conf/php-fpm.conf" # Into the restore script, the PHP-FPM template is not at the same place
|
|
||||||
fi
|
|
||||||
# Make sure now that the template indeed exists
|
# Make sure now that the template indeed exists
|
||||||
[ -e "$phpfpm_path" ] || ynh_die --message="Unable to find template to configure PHP-FPM."
|
[ -e "$phpfpm_path" ] || ynh_die --message="Unable to find template to configure PHP-FPM."
|
||||||
else
|
else
|
||||||
|
@ -169,7 +166,7 @@ ynh_add_fpm_config () {
|
||||||
# Define the values to use for the configuration of PHP.
|
# Define the values to use for the configuration of PHP.
|
||||||
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
ynh_get_scalable_phpfpm --usage=$usage --footprint=$footprint
|
||||||
|
|
||||||
local phpfpm_path="../conf/php-fpm.conf"
|
local phpfpm_path="$YNH_APP_BASEDIR/conf/php-fpm.conf"
|
||||||
echo "
|
echo "
|
||||||
[__APP__]
|
[__APP__]
|
||||||
|
|
||||||
|
@ -204,18 +201,18 @@ pm.process_idle_timeout = 10s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Concatene the extra config.
|
# Concatene the extra config.
|
||||||
if [ -e ../conf/extra_php-fpm.conf ]; then
|
if [ -e $YNH_APP_BASEDIR/conf/extra_php-fpm.conf ]; then
|
||||||
cat ../conf/extra_php-fpm.conf >> "$phpfpm_path"
|
cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >> "$phpfpm_path"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local finalphpconf="$fpm_config_dir/pool.d/$app.conf"
|
local finalphpconf="$fpm_config_dir/pool.d/$app.conf"
|
||||||
ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf"
|
ynh_add_config --template="$phpfpm_path" --destination="$finalphpconf"
|
||||||
|
|
||||||
if [ -e "../conf/php-fpm.ini" ]
|
if [ -e "$YNH_APP_BASEDIR/conf/php-fpm.ini" ]
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="Packagers ! Please do not use a separate php ini file, merge your directives in the pool file instead."
|
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"
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/php-fpm.ini" --destination="$fpm_config_dir/conf.d/20-$app.ini"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $dedicated_service -eq 1 ]
|
if [ $dedicated_service -eq 1 ]
|
||||||
|
@ -228,7 +225,7 @@ pid = /run/php/php__PHPVERSION__-fpm-__APP__.pid
|
||||||
error_log = /var/log/php/fpm-php.__APP__.log
|
error_log = /var/log/php/fpm-php.__APP__.log
|
||||||
syslog.ident = php-fpm-__APP__
|
syslog.ident = php-fpm-__APP__
|
||||||
include = __FINALPHPCONF__
|
include = __FINALPHPCONF__
|
||||||
" > ../conf/php-fpm-$app.conf
|
" > $YNH_APP_BASEDIR/conf/php-fpm-$app.conf
|
||||||
|
|
||||||
ynh_add_config --template="../config/php-fpm-$app.conf" --destination="$globalphpconf"
|
ynh_add_config --template="../config/php-fpm-$app.conf" --destination="$globalphpconf"
|
||||||
|
|
||||||
|
@ -245,7 +242,7 @@ ExecReload=/bin/kill -USR2 \$MAINPID
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
" > ../conf/$fpm_service
|
" > $YNH_APP_BASEDIR/conf/$fpm_service
|
||||||
|
|
||||||
# Create this dedicated PHP-FPM service
|
# Create this dedicated PHP-FPM service
|
||||||
ynh_add_systemd_config --service=$fpm_service --template=$fpm_service
|
ynh_add_systemd_config --service=$fpm_service --template=$fpm_service
|
||||||
|
|
|
@ -22,7 +22,7 @@ ynh_add_systemd_config () {
|
||||||
local service="${service:-$app}"
|
local service="${service:-$app}"
|
||||||
local template="${template:-systemd.service}"
|
local template="${template:-systemd.service}"
|
||||||
|
|
||||||
ynh_add_config --template="../conf/$template" --destination="/etc/systemd/system/$service.service"
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/$template" --destination="/etc/systemd/system/$service.service"
|
||||||
|
|
||||||
systemctl enable $service --quiet
|
systemctl enable $service --quiet
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
YNH_APP_BASEDIR=$([[ "$(basename $0)" =~ ^backup|restore$ ]] && echo '../settings' || echo '..')
|
||||||
|
|
||||||
# Handle script crashes / failures
|
# Handle script crashes / failures
|
||||||
#
|
#
|
||||||
# [internal]
|
# [internal]
|
||||||
|
@ -112,12 +114,7 @@ ynh_setup_source () {
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
source_id="${source_id:-app}" # If the argument is not given, source_id equals "app"
|
source_id="${source_id:-app}" # If the argument is not given, source_id equals "app"
|
||||||
|
|
||||||
local src_file_path="$YNH_CWD/../conf/${source_id}.src"
|
local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src"
|
||||||
# In case of restore script the src file is in an other path.
|
|
||||||
# So try to use the restore path if the general path point to no file.
|
|
||||||
if [ ! -e "$src_file_path" ]; then
|
|
||||||
src_file_path="$YNH_CWD/../settings/conf/${source_id}.src"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load value from configuration file (see above for a small doc about this file
|
# Load value from configuration file (see above for a small doc about this file
|
||||||
# format)
|
# format)
|
||||||
|
@ -309,10 +306,8 @@ ynh_add_config () {
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
local template_path
|
local template_path
|
||||||
|
|
||||||
if [ -f "../conf/$template" ]; then
|
if [ -f "$YNH_APP_BASEDIR/conf/$template" ]; then
|
||||||
template_path="../conf/$template"
|
template_path="$YNH_APP_BASEDIR/conf/$template"
|
||||||
elif [ -f "../settings/conf/$template" ]; then
|
|
||||||
template_path="../settings/conf/$template"
|
|
||||||
elif [ -f "$template" ]; then
|
elif [ -f "$template" ]; then
|
||||||
template_path=$template
|
template_path=$template
|
||||||
else
|
else
|
||||||
|
|
|
@ -704,9 +704,7 @@ class BackupManager:
|
||||||
settings_dir = os.path.join(self.work_dir, "apps", app, "settings")
|
settings_dir = os.path.join(self.work_dir, "apps", app, "settings")
|
||||||
|
|
||||||
logger.info(m18n.n("app_start_backup", app=app))
|
logger.info(m18n.n("app_start_backup", app=app))
|
||||||
tmp_script = (
|
tmp_folder = tempfile.mkdtemp()
|
||||||
None # This is to make sure the var exists later in the 'finally' ...
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
# Prepare backup directory for the app
|
# Prepare backup directory for the app
|
||||||
filesystem.mkdir(tmp_app_bkp_dir, 0o750, True, uid="admin")
|
filesystem.mkdir(tmp_app_bkp_dir, 0o750, True, uid="admin")
|
||||||
|
@ -715,8 +713,8 @@ class BackupManager:
|
||||||
shutil.copytree(app_setting_path, settings_dir)
|
shutil.copytree(app_setting_path, settings_dir)
|
||||||
|
|
||||||
# Copy app backup script in a temporary folder and execute it
|
# Copy app backup script in a temporary folder and execute it
|
||||||
_, tmp_script = tempfile.mkstemp(prefix="backup_")
|
|
||||||
app_script = os.path.join(app_setting_path, "scripts/backup")
|
app_script = os.path.join(app_setting_path, "scripts/backup")
|
||||||
|
tmp_script = os.path.join(tmp_folder, "backup")
|
||||||
subprocess.call(["install", "-Dm555", app_script, tmp_script])
|
subprocess.call(["install", "-Dm555", app_script, tmp_script])
|
||||||
|
|
||||||
hook_exec(
|
hook_exec(
|
||||||
|
@ -752,8 +750,8 @@ class BackupManager:
|
||||||
|
|
||||||
# Remove tmp files in all situations
|
# Remove tmp files in all situations
|
||||||
finally:
|
finally:
|
||||||
if tmp_script:
|
if tmp_folder and os.path.exists(tmp_folder):
|
||||||
filesystem.rm(tmp_script, force=True)
|
shutil.rmtree(tmp_folder)
|
||||||
filesystem.rm(env_dict["YNH_BACKUP_CSV"], force=True)
|
filesystem.rm(env_dict["YNH_BACKUP_CSV"], force=True)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Reference in a new issue