Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/install-openshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,25 @@ if [[ -n "$ACTIVE_OPENSHELL_BIN" && "$ACTIVE_OPENSHELL_BIN" = /* ]]; then
fi
fi

stage_nemoclaw_gateway_service() {
local gateway_bin="$1"
if [ "$OS" != "Linux" ]; then return 0; fi
if ! command -v systemctl >/dev/null 2>&1; then return 0; fi
if systemctl --user list-unit-files openshell-gateway.service --no-legend 2>/dev/null | grep -q .; then
info "Upstream openshell-gateway.service already present; skipping NemoClaw-owned unit."
return 0
fi
local unit_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
local env_dir="${XDG_STATE_HOME:-$HOME/.local/state}/nemoclaw/openshell-docker-gateway"
mkdir -p "$unit_dir" "$env_dir"
chmod 0700 "$env_dir"
sed "s|ExecStart=.*|ExecStart=$gateway_bin|" \
"$(dirname "$0")/nemoclaw-openshell-gateway.service" \
> "$unit_dir/nemoclaw-openshell-gateway.service"
systemctl --user daemon-reload 2>/dev/null || true
info "Staged NemoClaw-owned gateway service unit (not yet enabled). Onboarding will enable it."
}

install_bins() {
local dir="$1"
install -m 755 "$tmpdir/openshell" "$dir/openshell"
Expand Down Expand Up @@ -828,4 +847,6 @@ required_driver_bins_installed_in_dir "$target_dir" \
|| fail "OpenShell release '$RELEASE_TAG' did not install the required Docker-driver binaries."
require_openshell_messaging_features "$target_dir/openshell"

stage_nemoclaw_gateway_service "$target_dir/openshell-gateway"

info "$("$target_dir/openshell" --version 2>&1 || echo openshell) installed"
12 changes: 12 additions & 0 deletions scripts/nemoclaw-openshell-gateway.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add the required SPDX header.

Proposed fix
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
 [Unit]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` around lines 1 - 2, Add the
project-required SPDX license header at the beginning of the openshell gateway
service unit, before the [Unit] section, while preserving the existing
Description and service configuration.

Source: Coding guidelines

After=network.target

[Service]
EnvironmentFile=%h/.local/state/nemoclaw/openshell-docker-gateway/gateway.env

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the unit’s environment-file path aligned with XDG state.

This hard-codes $HOME/.local/state, but staging and onboarding write under $XDG_STATE_HOME when set. In that configuration, systemd reads a missing or stale file instead of the newly written gateway environment. Parameterize EnvironmentFile in the template and substitute the same env_dir/gateway.env path during staging.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` at line 6, Update the service
template’s EnvironmentFile to use a substitution for the gateway environment
path instead of hard-coding $HOME/.local/state, and ensure staging replaces that
placeholder with the same env_dir/gateway.env location used when writing the
gateway environment, including XDG_STATE_HOME overrides.

ExecStart=/usr/local/bin/openshell-gateway
Restart=on-failure
RestartSec=3

[Install]
WantedBy=default.target
Comment on lines +11 to +12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Enable lingering or this does not provide reboot persistence.

systemctl --user enable only starts this unit when the user manager runs; after reboot, that normally requires login unless lingering is enabled. A headless reboot therefore leaves the gateway down, contrary to the stated objective. Manage and validate user lingering, or explicitly narrow the supported lifecycle.

#!/bin/sh
loginctl show-user "$USER" -p Linger
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` around lines 11 - 12, Update the
service installation/setup flow associated with WantedBy=default.target to
manage and validate user lingering, ensuring the user manager starts after a
headless reboot and the gateway remains available without login. Use loginctl to
verify the target user’s Linger state and enable lingering when needed, or
explicitly narrow the documented lifecycle if lingering is not supported.

12 changes: 9 additions & 3 deletions src/lib/actions/uninstall/run-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { isModelRouterCommandLineForPort } from "../../onboard/model-router-proc
import { stopStaleDashboardListeners } from "../../onboard/stale-gateway-cleanup";
import { stopOpenRouterRuntimeAdapter } from "./openrouter-runtime-adapter-cleanup";
import { classifyShimPath, type FileSystemDeps } from "./plan";
import { uninstallNemoclawGatewayUserService } from "../../onboard/docker-driver-gateway-service";

export interface RunResult {
status: number | null;
Expand Down Expand Up @@ -939,10 +940,15 @@ function executePlan(
} else if (step.name === "State and binaries") {
removeManagedSwap(paths, runtime);
for (const pattern of paths.runtimeTempGlobs) removeGlob(pattern, runtime);
if (options.keepOpenShell) runtime.log("Keeping OpenShell binaries as requested.");
else
for (const target of paths.openshellInstallPaths)
if (options.keepOpenShell) {
runtime.log("Keeping OpenShell binaries as requested.");
runtime.log("Keeping NemoClaw-managed gateway service as requested.");
} else {
uninstallNemoclawGatewayUserService({ env: runtime.env });
for (const target of paths.openshellInstallPaths) {
removeFileWithOptionalSudo(target, runtime);
}
}
if (!removePathExcept(paths.nemoclawStateDir, preserveUnderStateDir, runtime)) ok = false;
removePath(paths.gatewayLocalStateDir, runtime);
removePath(paths.openshellConfigDir, runtime);
Expand Down
18 changes: 14 additions & 4 deletions src/lib/domain/uninstall/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type UninstallPlanAction =
| { kind: "stop-ollama-auth-proxy" }
| { kind: "stop-openshell-forward-processes" }
| { kind: "stop-orphaned-openshell-processes" }
| { kind: "uninstall-nemoclaw-gateway-service" }
| { kind: "preserve-nemoclaw-gateway-service" }
| { kind: "uninstall-npm-package"; name: "nemoclaw" };

export interface UninstallPlanStep {
Expand Down Expand Up @@ -125,11 +127,19 @@ export function buildUninstallPlan(
kind: "preserve-openshell-install-paths" as const,
paths: paths.openshellInstallPaths,
},
{
kind: "preserve-nemoclaw-gateway-service" as const,
},
]
: paths.openshellInstallPaths.map((path) => ({
kind: "delete-openshell-install-path" as const,
path,
}))),
: [
...paths.openshellInstallPaths.map((path) => ({
kind: "delete-openshell-install-path" as const,
path,
})),
{
kind: "uninstall-nemoclaw-gateway-service" as const,
},
]),
...uninstallStatePaths(paths).map((path) => ({ kind: "delete-path" as const, path })),
],
},
Expand Down
28 changes: 26 additions & 2 deletions src/lib/onboard/docker-driver-gateway-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import { buildDockerDriverGatewayLocalTlsEnv } from "./docker-driver-gateway-local-tls";
import {
hasOpenShellGatewayUserService,
hasNemoclawGatewayUserService,
getNemoclawGatewayEnvFilePath,
type PackageManagedDockerDriverGatewayOptions,
startPackageManagedDockerDriverGateway,
} from "./docker-driver-gateway-service";
Expand Down Expand Up @@ -272,6 +274,23 @@ function writeDockerGatewayDebEnvOverrideFile(getOverride: () => Record<string,
fs.chmodSync(envFile, 0o600);
}

export function writeNemoclawGatewayEnvFile(
getOverride: () => Record<string, string>,
opts: Parameters<typeof hasNemoclawGatewayUserService>[0] = {},
): void {
const override = getOverride();
const envFile = getNemoclawGatewayEnvFilePath(opts);
const envDir = path.dirname(envFile);
fs.mkdirSync(envDir, { recursive: true, mode: 0o700 });
fs.chmodSync(envDir, 0o700);
const existing = readTextFileIfPresent(envFile);
fs.writeFileSync(envFile, buildDockerGatewayDebEnvFile(existing, override), {
encoding: "utf-8",
mode: 0o600,
});
fs.chmodSync(envFile, 0o600);
}

export function writeDockerGatewayDebEnvOverride(
getOverride: () => Record<string, string>,
opts: Parameters<typeof hasOpenShellGatewayUserService>[0] = {},
Expand All @@ -297,7 +316,12 @@ export function startPackageManagedDockerDriverGatewayWithEnvOverride({
assertDockerDriverGatewayAuthConfigSafe(gatewayEnv);
return startPackageManagedDockerDriverGateway({
...options,
prepareOpenShellGatewayUserServiceEnv: () =>
writeDockerGatewayDebEnvOverrideFile(() => gatewayEnv),
prepareOpenShellGatewayUserServiceEnv: () => {
if (hasOpenShellGatewayUserService()) {
writeDockerGatewayDebEnvOverrideFile(() => gatewayEnv);
} else if (hasNemoclawGatewayUserService()) {
writeNemoclawGatewayEnvFile(() => gatewayEnv);
}
},
});
}
44 changes: 44 additions & 0 deletions src/lib/onboard/docker-driver-gateway-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
getOpenShellGatewayUserServiceBinaryPaths,
getOpenShellGatewayUserServicePaths,
hasOpenShellGatewayUserService,
hasNemoclawGatewayUserService,
uninstallNemoclawGatewayUserService,
type SpawnSyncLikeResult,
startOpenShellGatewayUserService,
startPackageManagedDockerDriverGateway,
Expand Down Expand Up @@ -77,6 +79,48 @@ describe("docker-driver-gateway-service", () => {
);
});

describe("nemoclaw-managed gateway service", () => {
it("detects the NemoClaw-managed service correctly on Linux", () => {
const existsSync = vi.fn((candidate: string) => candidate.includes("nemoclaw-openshell-gateway.service"));
expect(hasNemoclawGatewayUserService({ existsSync, platform: "linux", env: {} })).toBe(true);
expect(hasNemoclawGatewayUserService({ existsSync, platform: "darwin", env: {} })).toBe(false);
});

it("uninstalls the NemoClaw-managed service correctly", () => {
const events: string[] = [];
const spawnSyncImpl = vi.fn((_command: string, args: string[]) => {
events.push(args[1] ?? args[0] ?? "");
return spawnResult();
});

uninstallNemoclawGatewayUserService({
env: {},
existsSync: () => true,
platform: "linux",
spawnSyncImpl,
});

expect(events).toEqual(["disable", "daemon-reload"]);
});

it("does not run systemctl commands if NemoClaw-managed service does not exist", () => {
const events: string[] = [];
const spawnSyncImpl = vi.fn((_command: string, args: string[]) => {
events.push(args[1] ?? args[0] ?? "");
return spawnResult();
});

uninstallNemoclawGatewayUserService({
env: {},
existsSync: () => false,
platform: "linux",
spawnSyncImpl,
});

expect(events).toEqual([]);
});
});

it("restarts the upstream user service with systemctl --user after validating identity", () => {
const events: string[] = [];
const spawnSyncImpl = vi.fn((_command: string, args: string[]) => {
Expand Down
Loading
Loading