Mainly add external monitoring of mail server
[distro-setup] / primary-setup
index cc335d124814c42b80f849c29753b11a11da59ac..df30f294662019352acd32ac79d9251a7f391b87 100755 (executable)
@@ -18,6 +18,9 @@ fi
 
 if [[ $1 ]]; then
   new_host=$1
+  if [[ $new_host == localhost ]]; then
+    new_host=$HOSTNAME
+  fi
   m sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
   source /a/bin/bash_unpublished/source-state
 fi
@@ -44,6 +47,23 @@ else
   # done
 fi
 
+if dpkg -s radicale &>/dev/null; then
+  if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+    m sudo systemctl restart radicale
+    m sudo systemctl enable radicale
+    if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
+      m sudo mv /etc/logrotate.d/radicale{.disabled,}
+    fi
+  else
+    m sudo systemctl stop radicale
+    m sudo systemctl disable radicale
+    # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
+    if [[ -e /etc/logrotate.d/radicale ]]; then
+      m sudo mv /etc/logrotate.d/radicale{,.disabled}
+    fi
+  fi
+fi
+
 m /a/exe/mail-setup
 exit 0
 :