Feed domain list to regen-conf hooks directly through env to avoid having to call 'yunohost domain list'

This commit is contained in:
Alexandre Aubin 2020-04-25 03:49:30 +02:00
parent cf32853f81
commit 319898baf7
6 changed files with 22 additions and 26 deletions

View file

@ -14,7 +14,6 @@ do_pre_regen() {
# retrieve variables
main_domain=$(cat /etc/yunohost/current_host)
domain_list=$(yunohost domain list --output-as plain --quiet)
# install main conf file
cat metronome.cfg.lua \
@ -22,7 +21,7 @@ do_pre_regen() {
> "${metronome_dir}/metronome.cfg.lua"
# add domain conf files
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
cat domain.tpl.cfg.lua \
| sed "s/{{ domain }}/${domain}/g" \
> "${metronome_conf_dir}/${domain}.cfg.lua"
@ -33,7 +32,7 @@ do_pre_regen() {
| awk '/^[^\.]+\.[^\.]+.*\.cfg\.lua$/ { print $1 }')
for file in $conf_files; do
domain=${file%.cfg.lua}
[[ $domain_list =~ $domain ]] \
[[ $YNH_DOMAINS =~ $domain ]] \
|| touch "${metronome_conf_dir}/${file}"
done
}
@ -43,10 +42,9 @@ do_post_regen() {
# retrieve variables
main_domain=$(cat /etc/yunohost/current_host)
domain_list=$(yunohost domain list --output-as plain --quiet)
# create metronome directories for domains
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
mkdir -p "/var/lib/metronome/${domain//./%2e}/pep"
done
# http_upload directory must be writable by metronome and readable by nginx

View file

@ -46,7 +46,6 @@ do_pre_regen() {
# retrieve variables
main_domain=$(cat /etc/yunohost/current_host)
domain_list=$(yunohost domain list --output-as plain --quiet)
# Support different strategy for security configurations
export compatibility="$(yunohost settings get 'security.nginx.compatibility')"
@ -55,7 +54,7 @@ do_pre_regen() {
cert_status=$(yunohost domain cert-status --json)
# add domain conf files
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
domain_conf_dir="${nginx_conf_dir}/${domain}.d"
mkdir -p "$domain_conf_dir"
mail_autoconfig_dir="${pending_dir}/var/www/.well-known/${domain}/autoconfig/mail/"
@ -83,7 +82,7 @@ do_pre_regen() {
| awk '/^[^\.]+\.[^\.]+.*\.conf$/ { print $1 }')
for file in $conf_files; do
domain=${file%.conf}
[[ $domain_list =~ $domain ]] \
[[ $YNH_DOMAINS =~ $domain ]] \
|| touch "${nginx_conf_dir}/${file}"
done
@ -91,7 +90,7 @@ do_pre_regen() {
autoconfig_files=$(ls -1 /var/www/.well-known/*/autoconfig/mail/config-v1.1.xml 2>/dev/null || true)
for file in $autoconfig_files; do
domain=$(basename $(readlink -f $(dirname $file)/../..))
[[ $domain_list =~ $domain ]] \
[[ $YNH_DOMAINS =~ $domain ]] \
|| (mkdir -p "$(dirname ${pending_dir}/${file})" && touch "${pending_dir}/${file}")
done
@ -105,16 +104,13 @@ do_post_regen() {
[ -z "$regen_conf_files" ] && exit 0
# retrieve variables
domain_list=$(yunohost domain list --output-as plain --quiet)
# create NGINX conf directories for domains
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
mkdir -p "/etc/nginx/conf.d/${domain}.d"
done
# Get rid of legacy lets encrypt snippets
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
# If the legacy letsencrypt / acme-challenge domain-specific snippet is still there
if [ -e /etc/nginx/conf.d/${domain}.d/000-acmechallenge.conf ]
then

View file

@ -20,18 +20,17 @@ do_pre_regen() {
# prepare main.cf conf file
main_domain=$(cat /etc/yunohost/current_host)
domain_list=$(yunohost domain list --output-as plain --quiet | tr '\n' ' ')
# Support different strategy for security configurations
export compatibility="$(yunohost settings get 'security.postfix.compatibility')"
export main_domain
export domain_list
export domain_list="$YNH_DOMAINS"
ynh_render_template "main.cf" "${postfix_dir}/main.cf"
cat postsrsd \
| sed "s/{{ main_domain }}/${main_domain}/g" \
| sed "s/{{ domain_list }}/${domain_list}/g" \
| sed "s/{{ domain_list }}/${YNH_DOMAINS}/g" \
> "${default_dir}/postsrsd"
# adapt it for IPv4-only hosts

View file

@ -25,11 +25,8 @@ do_post_regen() {
mkdir -p /etc/dkim
chown _rspamd /etc/dkim
# retrieve domain list
domain_list=$(yunohost domain list --output-as plain --quiet)
# create DKIM key for domains
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
domain_key="/etc/dkim/${domain}.mail.key"
[ ! -f "$domain_key" ] && {
# We use a 1024 bit size because nsupdate doesn't seem to be able to

View file

@ -26,10 +26,9 @@ do_pre_regen() {
ynh_validate_ip4 "$ipv4" || ipv4='127.0.0.1'
ipv6=$(curl -s -6 https://ip6.yunohost.org 2>/dev/null || true)
ynh_validate_ip6 "$ipv6" || ipv6=''
domain_list=$(yunohost domain list --output-as plain --quiet)
# add domain conf files
for domain in $domain_list; do
for domain in $YNH_DOMAINS; do
cat domain.tpl \
| sed "s/{{ domain }}/${domain}/g" \
| sed "s/{{ ip }}/${ipv4}/g" \
@ -42,7 +41,7 @@ do_pre_regen() {
conf_files=$(ls -1 /etc/dnsmasq.d \
| awk '/^[^\.]+\.[^\.]+.*$/ { print $1 }')
for domain in $conf_files; do
[[ $domain_list =~ $domain ]] \
[[ $YNH_DOMAINS =~ $domain ]] \
|| touch "${dnsmasq_dir}/${domain}"
done
}

View file

@ -141,7 +141,14 @@ def regen_conf(operation_logger, names=[], with_diff=False, force=False, dry_run
if "glances" in names:
names.remove("glances")
pre_result = hook_callback('conf_regen', names, pre_callback=_pre_call)
# [Optimization] We compute and feed the domain list to the conf regen
# hooks to avoid having to call "yunohost domain list" so many times which
# ends up in wasted time (about 3~5 seconds per call on a RPi2)
from yunohost.domain import domain_list
env = {}
env["YNH_DOMAINS"] = " ".join(domain_list()["domains"])
pre_result = hook_callback('conf_regen', names, pre_callback=_pre_call, env=env)
# Keep only the hook names with at least one success
names = [hook for hook, infos in pre_result.items()
@ -310,7 +317,7 @@ def regen_conf(operation_logger, names=[], with_diff=False, force=False, dry_run
regen_conf_files = ''
return post_args + [regen_conf_files, ]
hook_callback('conf_regen', names, pre_callback=_pre_call)
hook_callback('conf_regen', names, pre_callback=_pre_call, env=env)
operation_logger.success()