From a79bb29699ff201c44d80dbced6b0a41d965adb7 Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Tue, 7 Jul 2026 23:41:16 -0400 Subject: [PATCH] fix: service restart on upgrade and no-cache headers for SPA assets - postinst: restart instead of start if service already enabled (upgrade case) - embed.go: no-cache/no-store on index.html, immutable cache on hashed assets - Fixes web not refreshing after dpkg upgrade --- Makefile | 2 +- internal/webui/embed.go | 9 +++++++-- packaging/debian/DEBIAN/postinst | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b9e5e01..d749020 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ package: build-all cp etc/syncserver/config.yaml dist/deb/etc/syncserver/config.yaml cp lib/systemd/system/$(BINARY).service dist/deb/lib/systemd/system/$(BINARY).service printf 'Package: $(BINARY)\nVersion: $(VERSION)\nSection: net\nPriority: optional\nArchitecture: amd64\nDepends: rsync, openssh-client, ca-certificates\nMaintainer: SyncServer\nDescription: File sync orchestrator with Wake-on-LAN and web UI\n' > dist/deb/DEBIAN/control - printf '#!/bin/sh\nset -e\nid $(BINARY) >/dev/null 2>&1 || useradd --system --no-create-home --shell /usr/sbin/nologin $(BINARY)\ninstall -d -o $(BINARY) -g $(BINARY) -m 0750 /var/lib/$(BINARY)/data\ninstall -d -o $(BINARY) -g $(BINARY) -m 0750 /var/lib/$(BINARY)/ssh\ninstall -d -o $(BINARY) -g $(BINARY) -m 0750 /var/lib/$(BINARY)/logs\ninstall -d -o root -g root -m 0755 /etc/$(BINARY)\n[ ! -f /etc/$(BINARY)/config.yaml ] && cp /etc/$(BINARY)/config.yaml /etc/$(BINARY)/config.yaml.new || true\nsystemctl daemon-reload 2>/dev/null || true\nsystemctl enable --now $(BINARY).service 2>/dev/null || true\n' > dist/deb/DEBIAN/postinst + printf '#!/bin/sh\nset -e\nSVC=$(BINARY)\nid $$SVC >/dev/null 2>&1 || useradd --system --no-create-home --shell /usr/sbin/nologin $$SVC\ninstall -d -o $$SVC -g $$SVC -m 0750 /var/lib/$$SVC/data\ninstall -d -o $$SVC -g $$SVC -m 0750 /var/lib/$$SVC/ssh\ninstall -d -o $$SVC -g $$SVC -m 0750 /var/lib/$$SVC/logs\ninstall -d -o root -g root -m 0755 /etc/$$SVC\n[ ! -f /etc/$$SVC/config.yaml ] && cp /etc/$$SVC/config.yaml /etc/$$SVC/config.yaml.new || true\nsystemctl daemon-reload 2>/dev/null || true\nif systemctl is-enabled --quiet $$SVC.service 2>/dev/null; then\n\tsystemctl restart $$SVC.service 2>/dev/null || true\nelse\n\tsystemctl enable --now $$SVC.service 2>/dev/null || true\nfi\n' > dist/deb/DEBIAN/postinst chmod 0755 dist/deb/DEBIAN/postinst printf '#!/bin/sh\nset -e\nsystemctl stop $(BINARY).service 2>/dev/null || true\nsystemctl disable $(BINARY).service 2>/dev/null || true\n' > dist/deb/DEBIAN/prerm chmod 0755 dist/deb/DEBIAN/prerm diff --git a/internal/webui/embed.go b/internal/webui/embed.go index cd4359e..4080b1c 100644 --- a/internal/webui/embed.go +++ b/internal/webui/embed.go @@ -16,6 +16,7 @@ func ServeHTTP() http.Handler { } func ServeSPA() http.Handler { + fsHandler := http.FileServer(http.FS(distSub)) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { path := r.URL.Path if path == "/favicon.ico" { @@ -28,11 +29,15 @@ func ServeSPA() http.Handler { http.Error(w, "not found", http.StatusNotFound) return } - w.Header().Set("Content-Type", "text/html") + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + w.Header().Set("Pragma", "no-cache") + w.Header().Set("Expires", "0") w.Write(data) return } - http.FileServer(http.FS(distSub)).ServeHTTP(w, r) + w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") + fsHandler.ServeHTTP(w, r) }) } diff --git a/packaging/debian/DEBIAN/postinst b/packaging/debian/DEBIAN/postinst index 4a024dd..ed5a058 100755 --- a/packaging/debian/DEBIAN/postinst +++ b/packaging/debian/DEBIAN/postinst @@ -35,8 +35,11 @@ EOF if command -v systemctl > /dev/null 2>&1; then systemctl daemon-reload 2>/dev/null || true - systemctl enable syncserver.service 2>/dev/null || true - systemctl start syncserver.service 2>/dev/null || true + if systemctl is-enabled --quiet syncserver.service 2>/dev/null; then + systemctl restart syncserver.service 2>/dev/null || true + else + systemctl enable --now syncserver.service 2>/dev/null || true + fi fi ;;