wip, less service restarts to avoid nn bug
authorIan Kelling <ian@iankelling.org>
Fri, 16 May 2025 04:07:56 +0000 (00:07 -0400)
committerIan Kelling <ian@iankelling.org>
Fri, 16 May 2025 04:07:56 +0000 (00:07 -0400)
mail-setup

index 3faf0af8f0af3e2e516f2ed5f70a97b85c8217b9..2d62531f8a24a2dd404243fc52094bff75187c66 100755 (executable)
@@ -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)