Restart pimonitor.service on upgrade if already running#76
Merged
Conversation
'systemctl enable --now' is a no-op when the unit is already active, so running install.sh to upgrade an already-installed PiMonitor replaced the binary and unit files but left the old process running until an unrelated reboot/restart. The dashboard footer version would then silently disagree with what was just installed. Detect whether the service was active before daemon-reload/enable, and explicitly restart it afterwards if so. Closes #59
LarsLaskowski
commented
Jul 17, 2026
Owner
Author
There was a problem hiding this comment.
Reviewed against the repo's review checklist. Checked out the branch and ran go build ./..., go vet ./..., go test ./... — all pass (as expected, the diff doesn't touch Go code). bash -n packaging/install.sh is clean.
The fix itself is correct:
systemctl is-activeis wrapped in anif, so its non-zero exit on an inactive/failed service doesn't tripset -euo pipefail.- The state is captured before
daemon-reload/enable --nowand the restart runs after the new unit file is loaded, so both a new binary and changed unit settings take effect — exactly the failure mode described in #59. - Edge cases behave sensibly: a
failedorinactiveservice reports not-active and gets a fresh start fromenable --nowwith the new binary anyway, so nothing is missed. - The updated usage comment now matches actual behavior.
Two non-blocking observations, no change requested:
- An equivalent, slightly simpler shape would be
systemctl enable pimonitor.servicefollowed by an unconditionalsystemctl restart pimonitor.service(restart also starts an inactive unit), which drops the state variable. The explicit version here is arguably clearer about why, so fine either way. pimonitor-apt-update.timerhas the same latent issue this PR fixes for the service: if a future release changes the timer's schedule,enable --nowon the already-running timer won't apply it. Out of scope for #59, but worth remembering if the timer definition ever changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packaging/install.shreplaces the/usr/local/bin/pimonitorbinary and thesystemd unit files on every run, then calls
systemctl enable --now pimonitor.service. That command is a no-op when the unit is already active,so re-running the installer to upgrade an already-installed PiMonitor left
the old binary running until an unrelated reboot/restart — the dashboard
footer version would silently disagree with what was just installed.
The script now records whether
pimonitor.servicewas active beforedaemon-reload/enable --now, and explicitly runssystemctl restart pimonitor.serviceafterwards if it was. This also picks up any changedsystemd unit settings for an already-running service, not just the binary.
The top-of-file usage comment was updated to describe this behavior instead
of claiming re-running is purely a no-op.
Related Issue
Closes #59
Checklist
go test ./...passes locally)go vet ./...andgolangci-lint runare cleandocs/API.md),configuration (
README.md,packaging/pimonitor.example.yaml), orinstallation/packaging (
packaging/install.sh, systemd units)/api/v1/...response shapes, or a new APIversion was introduced instead
Note on verification:
install.shis a shell script with no Go unittest coverage; there's no test harness in this repo for it. I verified the
change with
bash -n(syntax) and by re-reading thesystemctlcontrol flow.
go build ./...,go vet ./...,go test ./..., andgolangci-lint runall pass, but they exercise the unrelated Go codebase,not this script. Actually exercising an upgrade-of-a-running-service on a
real systemd host (Raspberry Pi or otherwise) hasn't been done and would be
good to confirm before/after a release.