#15981: fix: include --profile in systemd service ExecStart
gateway
commands
stale
size: S
Cluster:
Gateway and Session Fixes
## Summary
Fixes a regression where multi-profile gateways could not start simultaneously after upgrading from v2026.2.6-3 to v2026.2.13.
## Root Cause
The issue occurred because:
1. Systemd service files generated by `openclaw setup` and `openclaw onboard` did not include the `--profile` parameter in the ExecStart line
2. When the gateway process started, the `--profile` flag was not passed on the command line
3. This caused the gateway process detection to not distinguish between different profiles
This caused the error: `gateway already running (pid xxx); lock timeout after 5000ms`
## Changes
- Added `profile` parameter to `resolveGatewayProgramArguments()` function
- Modified `buildGatewayInstallPlan()` to pass `env.OPENCLAW_PROFILE` to the program arguments builder
- The ExecStart line in systemd service files now includes `--profile <name>` when a non-default profile is used
## Testing
- Added new test cases for the profile parameter in `resolveGatewayProgramArguments()`
- All existing daemon-related tests pass (120 tests)
- Verified the program arguments include `--profile` when a profile is provided
- Verified the profile is trimmed of whitespace
- Verified empty profiles are handled correctly
Fixes openclaw/openclaw#15970
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes a regression where multiple profile-based gateways could not start simultaneously. The root cause was that systemd service files lacked the `--profile` parameter in their ExecStart command, causing the gateway lock mechanism to fail at distinguishing between different profile instances.
The fix adds profile support to `resolveGatewayProgramArguments()` in `src/daemon/program-args.ts:242` and threads the `OPENCLAW_PROFILE` environment variable through `buildGatewayInstallPlan()` in `src/commands/daemon-install-helpers.ts:51`. The implementation properly handles edge cases: empty profiles are omitted, whitespace is trimmed, and the profile parameter is only added when non-empty.
Test coverage is comprehensive with three new test cases covering the profile parameter, empty profile handling, and whitespace trimming in `src/daemon/program-args.test.ts:91-147`.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is straightforward and follows existing patterns. The profile parameter is properly validated before use (trimmed and checked for emptiness), preventing malformed arguments. The fix is backwards compatible - when no profile is specified, behavior is unchanged. Test coverage is thorough with three new test cases validating the core functionality and edge cases. The change is minimal and focused, touching only the necessary functions to thread the profile parameter from environment to program arguments.
- No files require special attention
<sub>Last reviewed commit: b06c924</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21459: fix(gateway): resolve port from profile config, not inherited env
by kkeeling · 2026-02-19
87.3%
#11159: fix(cli): parse --profile flag after subcommand name
by hclsys · 2026-02-07
82.0%
#9728: fix(gateway): browser.snapshot ignores profile parameter (#9723)
by divol89 · 2026-02-05
79.3%
#23301: Gateway: prevent dev reset from touching default profile state
by tristanmanchester · 2026-02-22
78.7%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
78.2%
#16016: fix: update systemd unit version on gateway restart
by jbold · 2026-02-14
77.7%
#5496: Fix: Windows path separators stripped in Gateway scheduled task
by giuliozelante · 2026-01-31
76.9%
#23666: fix(doctor): openclaw-browser.service falsely flagged as duplicate ...
by yinghaosang · 2026-02-22
76.1%
#9460: fix(gateway): clean up lock file on service stop
by zenchantlive · 2026-02-05
75.2%
#23584: fix(daemon): improve gateway service detection to avoid false posit...
by mohandshamada · 2026-02-22
74.8%