← Back to PRs

#16016: fix: update systemd unit version on gateway restart

by jbold open 2026-02-14 05:24 View on GitHub →
gateway stale size: XS
## 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