From 5e860f0481d671aac65fdf876bd3beeaacd203b4 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 16 May 2025 00:07:56 -0400 Subject: [PATCH] wip, less service restarts to avoid nn bug --- mail-setup | 55 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/mail-setup b/mail-setup index 3faf0af..2d62531 100755 --- a/mail-setup +++ b/mail-setup @@ -376,6 +376,7 @@ reload=false if [[ -e /var/local/mail-setup-reload ]]; then reload=true fi +declare -A modified_services source /a/bin/fai/fai/config/distro-install-common/bash-misc-funcs setini() { @@ -420,18 +421,18 @@ mailhost() { serverp() { case $HOSTNAME in li|bk|je) - return true + return 0 ;; esac - return false + return 1 } nn-hostp() { case $HOSTNAME in li|je) - return false + return 1 ;; esac - return true + return 0 } reifactive() { @@ -474,7 +475,7 @@ fi bhost_t=false case $HOSTNAME in $MAIL_HOST) : ;; - kd|x2|x3|kw|sy|bo|so|frodo) + kd|x2|x3|kw|sy|so|frodo) bhost_t=true ;; esac @@ -535,7 +536,7 @@ fi # # note: rspamd would need to be here if we were using it. Note: these # don't start, but they are enabled. -pi-nostart exim4 exim4-daemon-heavy spamassassin unbound clamav-daemon wireguard +pi-nostart exim4 exim4-daemon-heavy spamassassin unbound wireguard spamd_remove=spamassassin spamd_ser=spamd @@ -4365,24 +4366,14 @@ fi case $HOSTNAME in $MAIL_HOST|bk) - m systemctl --now enable mailnn mailnnroute + # If any of these have config changes, then restart them as needed: + # sre mailnn mailnnroute $vpnser + m systemctl --now enable mailnn mailnnroute $vpnser ;;& $MAIL_HOST) - # we use dns to start wg - if $reload; then - sre unbound - else - m systemctl --now enable unbound - fi - ;;& - $MAIL_HOST|bk) - # If these have changes, id rather manually restart it, id rather - # not restart and cause temporary errors - if $reload; then - sre $vpnser - else - m systemctl --now enable $vpnser - fi + # If this service's config changes, add a manual restart here. + # note: we use dns to start wireguard + m systemctl --now enable unbound ;;& bk) if ! systemctl is-active clamav-daemon >/dev/null; then @@ -4400,6 +4391,7 @@ case $HOSTNAME in $MAIL_HOST|bk|je) # start spamassassin/dovecot before exim. sre dovecot $myspam_ser mailtest-check + # Wait a bit before restarting exim, else I get a paniclog entry # like: spam acl condition: all spamd servers failed. But I'm tired # of waiting. I'll deal with this some other way. @@ -4416,6 +4408,25 @@ case $HOSTNAME in ;;& esac +## wip to only restart services that actually need restarting. +all_units=( + mailnn.service mailnnroute.service $vpnser.service + unbound.service + clamav-daemon.service + dovecot.service $myspam_ser.service mailtest-check.service + mailclean.timer + radicale.service +) +for unit in ${all_units[@]}; do + if [[ ${modified_services[$unit]} ]]; then + enabled=$(systemctl is-enabled $service 2>/dev/null ||:) + if [[ $enabled == enabled ]]; then + systemctl stop $service + systemctl start $service + fi + fi +done + # for debugging dns issues case $HOSTNAME in je|bk) -- 2.30.2