diff --git a/packages/ssh/src/tunnel.test.ts b/packages/ssh/src/tunnel.test.ts index 6f4f14ea9eb64..5f0f1d7b94692 100644 --- a/packages/ssh/src/tunnel.test.ts +++ b/packages/ssh/src/tunnel.test.ts @@ -142,7 +142,16 @@ const runArchiveRunner = Effect.fn("test.runArchiveRunner")( ); describe("ssh tunnel scripts", () => { - it.live.each(["launchd", "systemd", "none"] as const)( + const serviceManagers = [ + "launchd", + "systemd", + "systemd-unavailable", + "systemd-unavailable-xdg", + "systemd-unavailable-relative-xdg", + "systemd-unavailable-login-xdg", + "none", + ] as const; + it.live.each(serviceManagers)( "respects %s service ownership when the server is stopped", (manager) => Effect.gen(function* () { @@ -175,12 +184,27 @@ esac yield* fs.makeDirectory(agents, { recursive: true }); yield* fs.writeFileString(`${agents}/com.t3tools.t3code.service.plist`, "installed"); } + const xdgConfigHome = + manager === "systemd-unavailable-xdg" || manager === "systemd-unavailable-login-xdg" + ? `${root}/custom config` + : manager === "systemd-unavailable-relative-xdg" + ? "relative-config" + : undefined; + if (manager.startsWith("systemd-unavailable")) { + const units = `${manager === "systemd-unavailable-xdg" ? xdgConfigHome : `${root}/.config`}/systemd/user`; + yield* fs.makeDirectory(units, { recursive: true }); + yield* fs.writeFileString(`${units}/t3code.service`, "installed"); + } const ssh = ChildProcessSpawner.make((command) => { if (command._tag !== "StandardCommand") return Effect.die("Expected SSH command"); return spawner.spawn( ChildProcess.make("sh", ["-s", "--", "test-peer"], { ...command.options, - env: { HOME: root, PATH: `${bin}:/usr/bin:/bin` }, + env: { + HOME: root, + PATH: `${bin}:/usr/bin:/bin`, + ...(xdgConfigHome === undefined ? {} : { XDG_CONFIG_HOME: xdgConfigHome }), + }, extendEnv: false, }), ); diff --git a/packages/ssh/src/tunnel.ts b/packages/ssh/src/tunnel.ts index cb08ae9851c4e..7e0b94f155a5d 100644 --- a/packages/ssh/src/tunnel.ts +++ b/packages/ssh/src/tunnel.ts @@ -744,7 +744,14 @@ if [ -z "$REMOTE_PORT" ]; then fi ;; Linux) - if command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; then + SERVICE_UNIT="systemd/user/t3code.service" + SERVICE_CONFIG_HOME="$HOME/.config" + case "\${XDG_CONFIG_HOME:-}" in + /*) SERVICE_CONFIG_HOME="$XDG_CONFIG_HOME" ;; + esac + # The SSH login may have a different XDG home and no connection to the user manager. + if [ -f "$SERVICE_CONFIG_HOME/$SERVICE_UNIT" ] || [ -f "$HOME/.config/$SERVICE_UNIT" ] || + { command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; }; then SERVICE_INSTALLED=1 fi ;;