make exim and wireguard restart waiting for internet. untested
authorIan Kelling <ian@iankelling.org>
Wed, 16 Feb 2022 03:50:49 +0000 (22:50 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 16 Feb 2022 03:50:49 +0000 (22:50 -0500)
distro-end
epanic-clean
mail-setup

index ee6693c360dab7b690037dbfa763ca37a1f24326..67e7a4e009fe4b2718ea13d1743c66f130a290d8 100755 (executable)
@@ -573,6 +573,19 @@ sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattende
 # EOF
 
 if [[ -e /etc/wireguard/wghole.conf ]]; then
+  reload=false
+  if [[ ! -e /etc/systemd/system/wg-quick@wghole.service.d/override.conf ]]; then
+    reload=true
+  fi
+  sd /etc/systemd/system/wg-quick@wghole.service.d/override.conf <<'EOF'
+[Unit]
+StartLimitIntervalSec=0
+
+[Service]
+Restart=always
+RestartSec=60
+EOF
+  if $reload; then ser daemon-reload; fi
   sgo wg-quick@wghole
 fi
 
index 8c26855041437f27fb4de093a5432ec64d4739d7..354d88b935e10d8b555710b637269e2136e5a0a6 100755 (executable)
@@ -32,6 +32,14 @@ main() {
     return 0
   fi
 
+  # example line:
+  # 2022-02-09 22:08:14.683 [59759] socket bind() to port 25 for address 10.8.0.28 failed: Cannot assign requested address: daemon abandoned
+  if [[ -e /etc/systemd/system/exim4.service.d/backup.conf ]]; then
+    regex="socket bind() to port 25 for address"
+    grep "$regex" $pl >> $pl-archive ||:
+    sed -i "/$regex/d" $pl
+  fi
+
   # seems to randomly be caused by
   # Starting exim4-base housekeeping, exim4-base.service
   regex="^[^ ]* 00:00:0.* Failed writing transport results to pipe: Broken pipe$"
@@ -58,10 +66,10 @@ main() {
     # them. write lock happens less but can fit under the same rule.
     if (( count > 20 )); then
       cat $pl
-      elif ! $newlines; then
+    elif ! $newlines; then
       grep "$regex" $pl >>$pl-archive
       sed -i "/$regex/d" $pl
-      fi
+    fi
   fi
   ## end broken pipe ##
 
index ae3aabbe9067365500861c500a77ae08c3f17a66..702c1d348a0d74e1a16d873a00c9adcc3c8ea4b1 100755 (executable)
@@ -846,7 +846,7 @@ awk 'BEGIN { FS = ":" } ; $6 ~ /^\/home/ && $7 !~ /\/nologin$/ { print $1 }' /et
   case $HOSTNAME in
     $MAIL_HOST)
       sed -i "/^user:/d" /etc/aliases
-    ;;
+      ;;
     *)
       if ! grep -q "^$user:" /etc/aliases; then
         echo "$user: root" |m tee -a /etc/aliases
@@ -2423,10 +2423,10 @@ EOF
 
     # this avoids some error. i cant remember what. todo:
     # test it out and document why/if its needed.
-#     i /etc/exim4/host_local_deny_exceptions <<'EOF'
-# mail.fsf.org
-# *.posteo.de
-# EOF
+    #     i /etc/exim4/host_local_deny_exceptions <<'EOF'
+    # mail.fsf.org
+    # *.posteo.de
+    # EOF
 
     # cron email from smarthost hosts will automatically be to
     # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
@@ -2658,14 +2658,22 @@ backup_local:
 EOF
 
       # Bind to wghole to receive mailbackup.
-      # todo: will wghole fail to start without internet connectivity?
-      # if so, we need to set it automatically restart infinitely,
-      # and same with exim.
       wgholeip=$(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc/wireguard/wghole.conf)
       cat >>/etc/exim4/update-exim4.conf.conf <<EOF
 dc_other_hostnames='eximbackup.b8.nz'
 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
 EOF
+
+      # wghole & thus exim will fail to start without internet connectivity.
+      i /etc/systemd/system/exim4.service.d/backup.conf <<'EOF'
+[Unit]
+StartLimitIntervalSec=0
+
+[Service]
+Restart=always
+RestartSec=300
+EOF
+
     else
       cat >>/etc/exim4/update-exim4.conf.conf <<EOF
 # Note: If theres like a temporary problem where mail gets sent to
@@ -2673,6 +2681,7 @@ EOF
 # instead of a permanent 5xx.
 dc_local_interfaces='127.0.0.1;::1'
 EOF
+      rm -fv /etc/systemd/system/exim4.service.d/backup.conf
     fi
     cat >>/etc/exim4/update-exim4.conf.conf <<EOF
 dc_eximconfig_configtype='smarthost'
@@ -2700,9 +2709,9 @@ case $HOSTNAME in
     m rsync -ra --delete /etc/exim4/ /etc/myexim4
     # If we ever wanted to have a separate spool,
     # we could do it like this.
-#     cat >>/etc/exim4/conf.d/main/000_local-nn <<'EOF'
-# spool_directory = /var/spool/myexim4
-# EOF
+    #     cat >>/etc/exim4/conf.d/main/000_local-nn <<'EOF'
+    # spool_directory = /var/spool/myexim4
+    # EOF
     cat >>/etc/myexim4/update-exim4.conf.conf <<'EOF'
 dc_eximconfig_configtype='smarthost'
 dc_smarthost='nn.b8.nz'
@@ -2874,7 +2883,7 @@ sre exim4
 case $HOSTNAME in
   $MAIL_HOST)
     m systemctl --now enable mailbindwatchdog
-  ;;
+    ;;
   *)
     soff mailbindwatchdog
     ;;