fix(postinst): robust service restart on upgrade

- Always enable service (not conditional on is-enabled)
- try-restart: reinicia si ya estaba corriendo
- start fallback: arranca si quedó inactive después del try-restart
- Covers: fresh install, running disabled, stopped manual, failed
- Like baby-nas but handles the "running-but-not-enabled" edge case
This commit is contained in:
2026-07-07 23:54:08 -04:00
parent 1e516cb746
commit f5f3b2263e
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ package: build-all
cp etc/syncserver/config.yaml dist/deb/etc/syncserver/config.yaml cp etc/syncserver/config.yaml dist/deb/etc/syncserver/config.yaml
cp lib/systemd/system/$(BINARY).service dist/deb/lib/systemd/system/$(BINARY).service 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 '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\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\nsystemctl is-enabled --quiet $$SVC.service 2>/dev/null && systemctl enable $$SVC.service 2>/dev/null || true\nsystemctl try-restart $$SVC.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\nsystemctl enable $$SVC.service 2>/dev/null || true\nsystemctl try-restart $$SVC.service 2>/dev/null || true\nif ! systemctl is-active --quiet $$SVC.service 2>/dev/null; then\n\tsystemctl start $$SVC.service 2>/dev/null || true\nfi\n' > dist/deb/DEBIAN/postinst
chmod 0755 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 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 chmod 0755 dist/deb/DEBIAN/prerm
+4 -1
View File
@@ -35,8 +35,11 @@ EOF
if command -v systemctl > /dev/null 2>&1; then if command -v systemctl > /dev/null 2>&1; then
systemctl daemon-reload 2>/dev/null || true systemctl daemon-reload 2>/dev/null || true
systemctl is-enabled --quiet syncserver.service 2>/dev/null && systemctl enable syncserver.service 2>/dev/null || true systemctl enable syncserver.service 2>/dev/null || true
systemctl try-restart syncserver.service 2>/dev/null || true systemctl try-restart syncserver.service 2>/dev/null || true
if ! systemctl is-active --quiet syncserver.service; then
systemctl start syncserver.service 2>/dev/null || true
fi
fi fi
;; ;;