diff --git a/update.sh b/update.sh index bedb8fc..3058925 100755 --- a/update.sh +++ b/update.sh @@ -215,6 +215,77 @@ if [[ -d "$BUILD_DIR/public" ]]; then fi log "Frontend eingespielt" +# ── systemd Units synchronisieren ───────────────────────────────────────── +# install.sh schreibt die Unit-Dateien nur beim Erst-Setup. Ohne diesen +# Schritt bleiben bereits installierte Server auf dem Stand von damals +# eingefroren, selbst wenn sich die Unit-Definition im Repo ändert (z.B. +# CAP_NET_ADMIN für die Security-Tab-Firewall-Aktion, nachträglich ergänzt — +# Server die vor dieser Änderung installiert wurden, hatten die Capability +# bis zu diesem Fix hier gefehlt). Bei jedem Deploy neu schreiben + reload, +# damit Unit-Änderungen aus install.sh automatisch nachgezogen werden. +info "Synchronisiere systemd Units..." +STORE_DIR="/var/archivmail" +LOG_DIR="/var/log/archivmail" +CONFIG_DIR="/etc/archivmail" +SSL_DIR="/etc/ssl/archivmail" +AM_USER="archivmail" + +cat > /etc/systemd/system/archivmail.service << UNIT +[Unit] +Description=archivmail Mail Archive Daemon +After=network.target postgresql.service manticore.service +Requires=postgresql.service manticore.service + +[Service] +Type=simple +User=${AM_USER} +Group=${AM_USER} +# CAP_NET_ADMIN: required for the admin "enable firewall" action (nft -f /etc/nftables.conf) +AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +ExecStart=${INSTALL_DIR}/archivmail --config ${CONFIG_DIR}/config.yml +ExecReload=/bin/kill -HUP \$MAINPID +Restart=on-failure +RestartSec=5 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=archivmail +NoNewPrivileges=false +ProtectSystem=strict +ReadWritePaths=${STORE_DIR} ${LOG_DIR} +ReadOnlyPaths=${CONFIG_DIR} ${SSL_DIR} + +[Install] +WantedBy=multi-user.target +UNIT + +cat > /etc/systemd/system/archivmail-web.service << UNIT +[Unit] +Description=archivmail Web Frontend +After=network.target archivmail.service + +[Service] +Type=simple +User=${AM_USER} +Group=${AM_USER} +WorkingDirectory=${INSTALL_DIR}/web +ExecStart=/usr/bin/node server.js +Environment=NODE_ENV=production +Environment=PORT=3000 +Restart=on-failure +RestartSec=5 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=archivmail-web + +[Install] +WantedBy=multi-user.target +UNIT + +systemctl daemon-reload +systemctl enable archivmail archivmail-web --quiet +log "systemd Units synchronisiert" + # ── Dienste starten ─────────────────────────────────────────────────────── info "Starte Dienste..."