← Back to PRs

#20357: feat(gateway): make systemd KillMode configurable for gateway install

by Jackten open 2026-02-18 20:40 View on GitHub →
gateway cli size: M
Closes #11257 ## Summary This PR makes systemd `KillMode` configurable for gateway service installs on Linux while preserving current behavior by default. - Adds `--systemd-kill-mode <mode>` to `openclaw gateway install` - Valid values: `process`, `mixed`, `control-group` - Defaults to `process` when flag is omitted (no behavior change) - Wires selected mode into generated systemd unit - Adds tests for default + override behavior and CLI validation/forwarding ## Why Issue: `#11257` Some deployments running heavy browser automation observed orphaned browser children surviving gateway restarts when unit files use `KillMode=process` and shutdown paths are bypassed. Making this configurable gives operators an explicit service-manager safety lever (`mixed` / `control-group`) without breaking existing podman-oriented default behavior. Reference evidence comment: - https://github.com/openclaw/openclaw/issues/11257#issuecomment-3923032592 ## Design - Keep default `KillMode=process` in systemd unit builder - Add typed KillMode constants/type in daemon layer - Thread optional `systemdKillMode` through service install API - Parse and validate CLI input in `runDaemonInstall` - On non-Linux platforms, accept option but emit warning and ignore it ## Files changed - `src/daemon/systemd-unit.ts` - `src/daemon/systemd.ts` - `src/daemon/service.ts` - `src/cli/daemon-cli/types.ts` - `src/cli/daemon-cli/register-service-commands.ts` - `src/cli/daemon-cli/install.ts` - `src/daemon/systemd-unit.test.ts` (new) - `src/cli/daemon-cli/install.test.ts` (new) - `src/cli/daemon-cli/register-service-commands.test.ts` ## Testing Targeted tests run locally: ```bash pnpm -s vitest run \ src/cli/daemon-cli/install.test.ts \ src/daemon/systemd-unit.test.ts \ src/daemon/systemd.test.ts \ src/cli/daemon-cli/register-service-commands.test.ts ``` Result: 4 test files passed, 19 tests passed. Formatting/lint on touched files: ```bash pnpm -s oxfmt --check <touched-files> pnpm -s oxlint --type-aware <touched-files> ``` Both passed. ## Backward compatibility - Existing installs without the new flag continue generating `KillMode=process` - No change to non-systemd platforms ## AI assistance disclosure - [x] AI-assisted PR - [x] Fully tested (targeted unit/integration-relevant tests for changed paths) - [x] Prompt/session context available on request - [x] I understand and verified the code paths changed in this PR <!-- greptile_comment --> <h3>Greptile Summary</h3> Added configurable `KillMode` setting for systemd gateway installs via `--systemd-kill-mode` flag while preserving backward compatibility with `process` as default. Implementation correctly validates input, normalizes casing, threads the option through CLI layers to systemd unit generation, and warns on non-Linux platforms. - Added CLI flag `--systemd-kill-mode` with validation for values: `process`, `mixed`, `control-group` - Implemented input normalization (trim + lowercase) and validation in `install.ts:27-41` - Properly threaded through service install API with platform check - Added tests covering default behavior, override functionality, and input validation - Minor duplication: `SystemdKillMode` type defined in both `systemd-unit.ts` and `service-types.ts` <h3>Confidence Score: 4/5</h3> - Safe to merge with minor style consideration - Implementation is sound with proper validation, platform checks, backward compatibility, and test coverage. Only minor style issue is duplicate type definition across two files (functionally equivalent but creates maintenance overhead). Core logic correctly validates inputs, normalizes values, and safely ignores flag on non-Linux platforms. - No files require special attention <sub>Last reviewed commit: 55a7b98</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs