#16016: fix: update systemd unit version on gateway restart
gateway
stale
size: XS
Cluster:
Gateway and System Fixes
## Summary
Fixes #16012 — After upgrading OpenClaw, `systemctl status` reports a stale version because the systemd unit file is only written during `openclaw gateway install`, not on restart.
## What changed
`restartSystemdService()` in `src/daemon/systemd.ts` now checks if the unit file's `OPENCLAW_SERVICE_VERSION` differs from the running `VERSION`. If stale, it patches both `Description=` and `OPENCLAW_SERVICE_VERSION=` in the unit file, runs `daemon-reload`, then restarts.
Wrapped in try/catch so a failure to update the version never blocks the restart itself.
## Testing
- All 30 existing daemon/systemd tests pass (`systemd.test.ts`, `systemd-unit.test.ts`, `service-env.test.ts`)
- Linter (`oxlint`) and formatter (`oxfmt`) pass on the changed file
- `pnpm build` succeeds
- Tested locally: confirmed stale v2026.2.9 unit file with v2026.2.13 source
## AI Disclosure
- [x] AI-assisted (Claude via OpenClaw agent)
- [x] Fully tested locally
- [x] Author understands the change
One file changed, ~30 lines added.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Updated `restartSystemdService()` to automatically sync the systemd unit file version with the running OpenClaw version before restarting the service.
**Key changes:**
- Reads the existing unit file and extracts `OPENCLAW_SERVICE_VERSION` using regex
- Compares extracted version against `VERSION` from the codebase
- If versions differ, updates both the `Description=` line and `OPENCLAW_SERVICE_VERSION=` environment variable
- Runs `daemon-reload` after updating the unit file to ensure systemd picks up changes
- Wrapped in try/catch to ensure restart proceeds even if version update fails
- Provides user feedback showing the version transition (e.g., "v2026.2.9 → v2026.2.13")
This ensures `systemctl status` displays the correct version after upgrading OpenClaw, addressing the issue where the version was only set during initial `openclaw gateway install` and became stale on subsequent restarts.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is well-designed with proper error handling (try/catch ensures restart never fails due to version update issues), uses appropriate regex patterns that target distinct parts of the unit file, follows existing code patterns in the codebase, includes defensive programming practices, and all existing tests pass according to the PR description
- No files require special attention
<sub>Last reviewed commit: 8387855</sub>
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16185: fix: patch systemd unit version before service restart
by nozh · 2026-02-14
89.9%
#21212: fix: detect and manage systemd system services (rebased)
by growthringsadvisory · 2026-02-19
82.9%
#11974: [FEATURE] feat: integrate systemd WatchdogSec for gateway hang dete...
by mcaxtr · 2026-02-08
80.9%
#22108: fix: prevent local DoS by fully clearing systemd services on uninstall
by berkeserce · 2026-02-20
80.7%
#9036: fix: add systemd restart limits to prevent infinite crash-loops
by joetomasone · 2026-02-04
80.2%
#23113: fix: show actual runtime version after update/restart when service ...
by BryanTegomoh · 2026-02-22
79.6%
#17237: fix(update): guard post-install imports after npm global update
by tdjackey · 2026-02-15
79.5%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
79.3%
#9156: fix(status): refresh version/commit on gateway restart
by gavinbmoore · 2026-02-04
78.7%
#12804: fix(daemon): use wrapper script for pnpm global installs in service...
by odinho · 2026-02-09
78.6%