#9036: fix: add systemd restart limits to prevent infinite crash-loops
gateway
stale
Cluster:
Gateway and System Fixes
## Problem
The generated systemd unit file has `Restart=always` but no limits on restart attempts. When the gateway crashes on startup (e.g., due to invalid config), systemd restarts it forever until manual intervention.
This can result in hundreds of restart cycles, filling logs and wasting resources.
## Solution
Add restart limits to the `[Unit]` section of the generated systemd unit:
```ini
StartLimitIntervalSec=300
StartLimitBurst=5
```
This limits the gateway to **5 restart attempts within a 5-minute window**. After hitting the limit, systemd stops restarting and requires manual intervention (fix config, run `openclaw doctor`, then restart).
## Impact
- **New installs**: Will have the limits automatically
- **Existing installs**: Need to regenerate the service file (`openclaw gateway install`) to get the new settings
## Testing
Generated unit file now includes:
```ini
[Unit]
Description=OpenClaw Gateway
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=300
StartLimitBurst=5
```
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Updates the generated systemd unit template in `src/daemon/systemd-unit.ts` to add `StartLimitIntervalSec=300` and `StartLimitBurst=5` under the `[Unit]` section. This complements the existing `Restart=always`/`RestartSec=5` service settings by preventing unbounded restart loops when the gateway repeatedly fails on startup (e.g., invalid configuration).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is limited in scope (two additional systemd unit directives) and is placed in the correct section (`[Unit]`), aligning with systemd semantics for start-rate limiting while leaving existing service behavior unchanged outside restart throttling.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16016: fix: update systemd unit version on gateway restart
by jbold · 2026-02-14
80.2%
#14259: fix(discord): add timeout to restart to prevent duplicate responses
by George5562 · 2026-02-11
78.9%
#13084: fix(daemon): multi-layer defense against zombie gateway processes
by openperf · 2026-02-10
77.2%
#20629: fix: use KillMode=mixed to prevent orphaned child processes
by alexander-morris · 2026-02-19
76.3%
#11974: [FEATURE] feat: integrate systemd WatchdogSec for gateway hang dete...
by mcaxtr · 2026-02-08
75.1%
#16185: fix: patch systemd unit version before service restart
by nozh · 2026-02-14
74.2%
#9460: fix(gateway): clean up lock file on service stop
by zenchantlive · 2026-02-05
73.8%
#20357: feat(gateway): make systemd KillMode configurable for gateway install
by Jackten · 2026-02-18
73.7%
#15981: fix: include --profile in systemd service ExecStart
by MisterGuy420 · 2026-02-14
73.7%
#22108: fix: prevent local DoS by fully clearing systemd services on uninstall
by berkeserce · 2026-02-20
73.4%